Practical File Programs
Practical File Programs
2. Write a python program to input two numbers and display the larger / smaller number.
#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.
for i in range(1,6):
for j in range(1,i+1):
print("*",end=" ")
print()
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
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