Cs Practical File Class 11
Cs Practical File Class 11
Cs Practical File Class 11
5 Write a program to input the value of x and n and print the sum of the following
series:
a. 1 + x² + x³ + ... + xⁿ
b. x - x2/2! + x3/3! - x4/4! + x5/5! - x6/6!
6 Write a program to determine whether a number is a perfect number, an
Armstrong number or a palindrome.
7 Write a program to input a number and check if the number is a prime or
composite number.
8 Write a program to display the n terms of a Fibonacci series.
9 Write a python program to compute the greatest common divisor and least
common multiple of two integers.
10 Write a program to count and display the number of vowels, consonants,
uppercase, lowercase characters in string.
1. Write a python program to input a welcome message and display it.
wl_msg = input(“Enter the welcome message:”)
print(wl_msg)
2. Write a python program to input two numbers and display the larger / smaller number.
n1=int(input(“Enter number1 n1=input("Enter the first
number to check:")
n2=input("Enter the second number to check:")
#Checking Larger
if n1>n2:
print(n1," is larger.")
elif n2>n1:
print(n2," is larger")
else:
print("You have entered equal number.")
#Checking Smaller
if n1<n2:
print(n1," is smaller.")
elif n2<n1:
print(n2," is smaller")
else:
print("You have entered equal number.")
3. Write a python program to input three numbers and display the largest / smallest number.
n1=input("Enter the first number to check:")
n2=input("Enter the second number to check:")
n3=input("Enter the third number to check:")
#Checking Largest
if n1>n2 and
n1>n3:
print(n1," is largest.")
elif n2>n1 and n2>n3:
print(n2," is largest")
elif n3>n1 and n3>n2:
print(n3," is largest")
else:
print("You have entered equal number.")
#Checking Smallest
if n1<n2 and n1<n3:
print(n1," is smallest.")
elif n2<n1 and n2<n3:
print(n2," is smallest")
elif n3<n1 and n3<n2:
print(n3," is smallest")
else:
print("You have entered equal number.")
4. Generate the following patterns using nested loop.
for i in range(1,6):
for j in range(1,i+1):
print("*",end=" ")
print()
for i in range(6,1,-1):
for j in range(1,i):
print(j,end=" ")
print()
for j in range(65,i+1):
print(chr(j),end="")
print()
5. Write a program to input the value of x and n and print the sum of the following series:
a. 1 + x² + x³ + ... + xⁿ
b. x - x2/2! + x3/3! - x4/4! + x5/5! - x6/6!
#Series 2
sum = 0
m = 1
for i in range(1, 7) :
f = 1
for j in range(1, i+1) :
f *= j
t = x ** i / f
if i==1:
print(int(t),end=" ")
elif i%2==0:
print("-",int(t),end=" ")
else:
print("+",int(t),end=" ")
sum += t * m
m = m * -1
print(" =", sum)
Series 1:
Series 2:
6. Write a program to determine whether a number is a perfect number, an Armstrong number or a
palindrome.
n=int(input("Enter a number to check:"))
temp = n
cnt=0
rev=0
7. Write a program to input a number and check if the number is a prime or composite number.
n=int(input("Enter number to check:"))
if n>1:
for i in range(2,n):
if n%i==0:
f=1
break
else:
f=0
elif n==0 or n==1:
print(n, " is not a prime number nor composite
number")
else:
print(n," is a composite number")
if f==1:
print(n, " is not a prime number")
else:
print(n," is a prime number")
8. Write a program to display the n term Fibonacci series.
nterms = int(input("Enter number of terms to display:
"))
9. Write a python program to compute the greatest common divisor and least common multiple of two
integers.
# Reading two numbers from user
fn = int(input('Enter first number: '))
sn = int(input('Enter second number: '))
gcd = 1
for i in range(1,fn +1):
if fn%i==0 and sn%i==0:
gcd = i
# Displaying GCD
print('HCF or GCD of %d and %d is %d' %(fn, sn,gcd))
# Calculating LCM
lcm = fn * sn/ gcd
print('LCM of %d and %d is %d' %(fn, sn, lcm))
10. Write a program to count and display the number of vowels, consonants, uppercase, lowercase
characters in string.
txt = input("Enter Your String : ")
v = c = uc = lc = 0
v_list = ['a','e','i','o','u']
for i in txt:
if i in v_list:
v += 1
if i not in v_list:
c += 1
if i.isupper():
uc += 1
if i.islower():
lc += 1