LAB 5i

You might also like

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

LAB-5

 Write a program using function which does the following


1. Count the number of digits in a number
2. Find the product of odd digits in a number
3. Generate first 10 Mersenne Numbers
4. To display the Fibonacci series up to a limit

def count (n):


c=0
while n>0:
c+=1
n//=10
print('No of Digits=',c)
def product(n):
p=1
f=0
while n>0:

if n%2!=0:
r=n%10
p*=r
f=1
n//=10
1|Page
if f==0:
print('No Odd Digits in the number')
else:
print('Product of Odd digits=',p)
def mersenne():
print('Mersenne Numbers are:')
for i in range(1,11):
print(2**i-1,end=' ')
print()
def fibonacci(n):
n1,n2=0,1
print(n1,'\t',n2,end='\t')
for i in range (n-2):
n3=n1+n2
print(n3,end='\t')
n1,n2=n2,n3
print()
while True:
print('1.COUNT THE NO OF DIGITS')
print('2.PRODUCT OF ODD DIGITS ')
print('3.FIRST 10 MERSENNE NUMBERS')
print('4.FIBONACCI SERIES')
print('5.EXIT')
ch=int(input('Enter ur choice:'))
2|Page
if ch==1:
n=int(input('Enter the number:'))
count(n)
elif ch==2:
n=int(input('Enter the number:'))
product(n)
elif ch==3:
mersenne()
elif ch==4:
n=int(input('Enter the limit:'))
fibonacci(n)
else:
print('INVALID CHOICE')
break

3|Page
4|Page

You might also like