Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Class: XI (Science), Session, 2020-2021

Laboratory File

By: Subhojit Ghosh


Subject: Computer Science, code (083)
1 Write a Program to check whether the user is eligible for Driving License. 3

2 Write a Program to calculate the sum of following series 1+ (1+2) + (1+2+3) 4


+…………..+(1+2+3+…..+n)

3 Write a Program to Print table of Given number. (User Will enter the 5
number)

4 Write a Program to generate the sequence : -5,10,-15,20,..........up to n , 6


where n is an integer entered by the user

5 Write a Program to check whether a number is palindrome or not 7

6 Write a Program to check whether a number is an Armstrong or not. 8

7 Write a Program to input a number and calculate its double factorial 9

8 Write a Program to print following pattern : 10


12345
1234
123
12
1

9 Write a Program to print Fibonacci Series 11

10 Write a Program to find sum of series: s=1+x+x2+.............+xn. 12

Sr Programs Page
.No Number
# 1. Write a Program to check whether the user is eligible for Driving License.

name=input("Enter Your Name :")

age=int(input("Enter your Age:"))

if (age>=18):

print(name," is eligible for a Driving License.")

else:

print(name," is not eligible for a Driving License.")

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>>

==== RESTART: C:/Users/Subhojit/AppData/Local/Programs/Python/Python39/P1.py ===

Enter Your Name :Subhojit Ghosh

Enter your Age:16

Subhojit Ghosh is not eligible for a Driving License.

>>>
# 2. Write a Program to calculate the sum of following series 1+ (1+2) + (1+2+3) +…………..+(1+2+3+…..+n)

sum=0

n=int(input("How many terms:"))

#added 2 to n because started with 2

for a in range(2,(n+2)):

term=0

for b in range(1,a):

term+=b

print("Term",(a-1),":",term)

sum+=term

print("Sum of",n,"terms is",sum)

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>>

========= RESTART: C:/Users/Subhojit/Desktop/CLASS XI CSC PROJECT/p1.py ========

How many terms:5

Term 1 : 1

Term 2 : 3

Term 3 : 6

Term 4 : 10

Term 5 : 15

Sum of 5 terms is 35

>>>
#3. Write a Program to Print table of Given number. (User Will enter the number)

n=int(input("Enter Any Number:"))

for i in range(1,11):

print(n,"*",i," = ",(n*i))

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>>

==== RESTART: C:/Users/Subhojit/AppData/Local/Programs/Python/Python39/P1.py ===

Enter Any Number:6

6*1=6

6 * 2 = 12

6 * 3 = 18

6 * 4 = 24

6 * 5 = 30

6 * 6 = 36

6 * 7 = 42

6 * 8 = 48

6 * 9 = 54

6 * 10 = 60

>>>
#4. Write a Program to generate the sequence : -5,10,-15,20,..........upto n , where n is an integer entered by
the user

n=int(input("Enter the Limit:"))

sign=-1

for i in range(5,n,5):

term=i*sign

sign=sign*(-1)

print(term, end =",")

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>>

==== RESTART: C:/Users/Subhojit/AppData/Local/Programs/Python/Python39/P1.py ===

Enter the Limit:50

-5,10,-15,20,-25,30,-35,40,-45,

>>>
# 5. Write a Program to check whether a number is palindrome or not.

n=int(input("enter Any Number:"))

temp=n

rev=0

while temp>0:

digit=temp%10

rev=(rev*10)+digit

temp//=10

if n==rev:

print( n ," is a palindrome Number")

else:

print( n ," is not a palindrome Number")

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>>

==== RESTART: C:/Users/Subhojit/AppData/Local/Programs/Python/Python39/P1.py ===

enter Any Number:1221

1221 is a palindrome Number

>>>
#6. Write a Program to check whether a number is an Armstrong or not.

n=int(input("enter Any Number:"))

temp=n

rev=0

while temp>0:

digit=temp%10

rev= rev+(digit**3)

temp//=10

if n==rev:

print( n ," is an Armstrong Number")

else:

print( n ," is not an Armstrong Number")

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>>

==== RESTART: C:/Users/Subhojit/AppData/Local/Programs/Python/Python39/P1.py ===

enter Any Number:153

153 is an Armstrong Number

>>>
# 7. Write a Program to input a number and calculate its double factorial.

n=int(input("enter Any Number:"))

fact = 1

for i in range(n,0,-2):

fact*=i

print(n,"!! is :",fact)

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>>

==== RESTART: C:/Users/Subhojit/AppData/Local/Programs/Python/Python39/P1.py ===

enter Any Number:7

7 !! is : 105

>>>
#8. Write a Program to print following pattern.

12345

1234

123

12

n=int(input("enter Any Number:"))

s=0 # for intialspaces

for i in range(n,0,-1):

for j in range(1,(s+1)):

print(end=" ")

for j in range(1,(i+1)):

print(j,end=" ")

s+=2

print()

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>>

========= RESTART: C:/Users/Subhojit/Desktop/CLASS XI CSC PROJECT/p1.py ========

enter Any Number:5

12345

1234

123

12

>>>
# 9. Write a Program to print Fibonacci Series.

n=int(input("Enter how many times the loop will execute :"))

a,b=0,1

print(a)

print(b)

for i in range(2,n):

result=a+b

print(result)

a=b

b=result

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>>

==== RESTART: C:/Users/Subhojit/AppData/Local/Programs/Python/Python39/P1.py ===

Enter how many times the loop will execute :10

0,1,1,2,3,5,8,13,21,34
# 10. Write a Program to find sum of series: s=1+x+x2+.............+xn.

x=float(input("Enter value of x :"))

n=int(input("Enter value for n(for x**n ):"))

s=0

for a in range(n+1):

s=s+(x**a)

print("Sum of Series is :",s)

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>>

==== RESTART: C:/Users/Subhojit/AppData/Local/Programs/Python/Python39/P1.py ===

Enter value of x : 2

Enter value for n(for x**n ):10

Sum of Series is : 2047.0

>>>

You might also like