0% found this document useful (0 votes)
3 views9 pages

CS FInal

The document contains a practical record file with various Python programs that perform mathematical operations such as calculating the number of digits, sum, product, and checking properties of numbers (Armstrong, Palindrome, Perfect, Fibonacci, Prime). It includes user interaction through a menu-driven interface allowing users to choose different options for calculations. The programs utilize loops and conditionals to process user input and display results.

Uploaded by

shini2582
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

CS FInal

The document contains a practical record file with various Python programs that perform mathematical operations such as calculating the number of digits, sum, product, and checking properties of numbers (Armstrong, Palindrome, Perfect, Fibonacci, Prime). It includes user interaction through a menu-driven interface allowing users to choose different options for calculations. The programs utilize loops and conditionals to process user input and display results.

Uploaded by

shini2582
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

# Y.

Mukul Anand-11A-19-Practical Record File


#(1)
while True:
print('-'*10)
print('Exit (Option 0) ')
print('Calculate and display the no. of Digits?(Option 1) ')
print('Calculate and display the sum of Digits?(Option 2)')
print('Calculate and display the product of Digits?(Option 3)')
print('Calculate and display the number of Odd Digits and Even
Digits?(Option 4) ')
print('Calculate and display the sum of Odd Digits and sum of Even
Digits?(Option 5)')
print('Calculate and display the product of Odd Digits and Even
Digits?(Option 6)')
op=int(input('Enter your option: '))
if op==1:
n=int(input('Integer?'))
c=0
while n:
c+=1
n//=10
print('No. of Digits=',c)
if op==2:
# Sum of Digits
n=int(input('Integer?'))
s=0
while n:
d=n%10
s+=d
n//=10
print('Sum of Digits=',s)
if op==3:
# Product of Digits
n=int(input('Integer?'))
p=1
while n:
d=n%10
p*=d
n//=10
print('Product of Digits=',p)
if op==4:
# Number of Odd Digits and Even Digits
n=int(input('Integer?'))
ce=co=0
while n:
d=n%10
if d%2==0:
ce+=1
else:co+=1
n//=10
print('No. of Even Digits=',ce)
print('No. of Odd Digits=',co)
#Sum of Odd Digits and Sum of Even Digits
if op==5:
1
# Y.Mukul Anand-11A-19-Practical Record File
n=int(input('Integer?'))
se=so=0
while n:
d=n%10
if d%2==0:
se+=d
else:so+=d
n//=10
print('Sum of Even Digits=',se)
print('Sum of Odd Digits=',so)
if op==6:
# Product of Odd Digits and Even Digits
n=int(input('Integer?'))
pe=po=1
while n:
d=n%10
if d%2==0:
pe*=d
else:po*=d
n//=10
print('Product of Even Digits=',pe)
print('Product of Odd Digits=',po)
if op==0:
break
'''Sample Output
Exit (Option 0)
Calculate and display the no. of Digits?(Option 1)
Calculate and display the sum of Digits?(Option 2)
Calculate and display the product of Digits?(Option 3)
Calculate and display the number of Odd Digits and Even Digits?(Option
4)
Calculate and display the sum of Odd Digits and sum of Even Digits?
(Option 5)
Calculate and display the product of Odd Digits and Even Digits?(Option
6)
Enter your option: 1
Integer?1234
No. of Digits= 4
----------
Exit (Option 0)
Calculate and display the no. of Digits?(Option 1)
Calculate and display the sum of Digits?(Option 2)
Calculate and display the product of Digits?(Option 3)
Calculate and display the number of Odd Digits and Even Digits?(Option
4)
Calculate and display the sum of Odd Digits and sum of Even Digits?
(Option 5)
Calculate and display the product of Odd Digits and Even Digits?(Option
6)
Enter your option: 2
Integer?1234
Sum of Digits= 10
----------
2
# Y.Mukul Anand-11A-19-Practical Record File
Exit (Option 0)
Calculate and display the no. of Digits?(Option 1)
Calculate and display the sum of Digits?(Option 2)
Calculate and display the product of Digits?(Option 3)
Calculate and display the number of Odd Digits and Even Digits?(Option
4)
Calculate and display the sum of Odd Digits and sum of Even Digits?
(Option 5)
Calculate and display the product of Odd Digits and Even Digits?(Option
6)
Enter your option: 3
Integer?1234
Product of Digits= 24
----------
Exit (Option 0)
Calculate and display the no. of Digits?(Option 1)
Calculate and display the sum of Digits?(Option 2)
Calculate and display the product of Digits?(Option 3)
Calculate and display the number of Odd Digits and Even Digits?(Option
4)
Calculate and display the sum of Odd Digits and sum of Even Digits?
(Option 5)
Calculate and display the product of Odd Digits and Even Digits?(Option
6)
Enter your option: 4
Integer?1234
No. of Even Digits= 2
No. of Odd Digits= 2
----------
Exit (Option 0)
Calculate and display the no. of Digits?(Option 1)
Calculate and display the sum of Digits?(Option 2)
Calculate and display the product of Digits?(Option 3)
Calculate and display the number of Odd Digits and Even Digits?(Option
4)
Calculate and display the sum of Odd Digits and sum of Even Digits?
(Option 5)
Calculate and display the product of Odd Digits and Even Digits?(Option
6)
Enter your option: 5
Integer?1234
Sum of Even Digits= 6
Sum of Odd Digits= 4
----------
Exit (Option 0)
Calculate and display the no. of Digits?(Option 1)
Calculate and display the sum of Digits?(Option 2)
Calculate and display the product of Digits?(Option 3)
Calculate and display the number of Odd Digits and Even Digits?(Option
4)
Calculate and display the sum of Odd Digits and sum of Even Digits?
(Option 5)

3
# Y.Mukul Anand-11A-19-Practical Record File
Calculate and display the product of Odd Digits and Even Digits?(Option
6)
Enter your option: 6
Integer?1234
Product of Even Digits= 8
Product of Odd Digits= 3
----------
Exit (Option 0)
Calculate and display the no. of Digits?(Option 1)
Calculate and display the sum of Digits?(Option 2)
Calculate and display the product of Digits?(Option 3)
Calculate and display the number of Odd Digits and Even Digits?(Option
4)
Calculate and display the sum of Odd Digits and sum of Even Digits?
(Option 5)
Calculate and display the product of Odd Digits and Even Digits?(Option
6)
Enter your option: 0
'''
#(2)
while True:
print('-'*10)
print('Exit (Option 0)')
print('Check Armstrong Number?(Option 1)')
print('Check Palindrome Number?(Option 2)')
print('Check Perfect Number?(Option 3)')
op=int(input('Enter your option: '))
# Armstrong Number
if op==1:
t=n=m=int(input('Integer?'))
s=c=0
while n:
c+=1
n//=10
while m:
d=m%10
s+=d**c
m//=10
if s==t:
print('Armstrong Number')
else:print('Not Armstrong Number')
if op==2:
# Palindrome Number
t=n=int(input('Integer?'))
r=0
while n:
d=n%10
r=10*r+d
n//=10
if r==t:
print('Palindrome Number')
else:print('Not Palindrome Number')
if op==3:
4
# Y.Mukul Anand-11A-19-Practical Record File
# Perfect Number
n=int(input('Integer?'))
s=0
for x in range(1,n):
if n%x==0:
s+=x
if s==n:
print('Perfect Number')
else:print('Not Perfect Number')
if op==0:
break
'''Sample Output
----------
Exit (Option 0)
Check Armstrong Number?(Option 1)
Check Palindrome Number?(Option 2)
Check Perfect Number?(Option 3)
Enter your option: 1
Integer?153
Armstrong Number
----------
Exit (Option 0)
Check Armstrong Number?(Option 1)
Check Palindrome Number?(Option 2)
Check Perfect Number?(Option 3)
Enter your option: 1
Integer?12345
Not Armstrong Number
----------
Exit (Option 0)
Check Armstrong Number?(Option 1)
Check Palindrome Number?(Option 2)
Check Perfect Number?(Option 3)
Enter your option: 2
Integer?12321
Palindrome Number
----------
Exit (Option 0)
Check Armstrong Number?(Option 1)
Check Palindrome Number?(Option 2)
Check Perfect Number?(Option 3)
Enter your option: 2
Integer?5645
Not Palindrome Number
----------
Exit (Option 0)
Check Armstrong Number?(Option 1)
Check Palindrome Number?(Option 2)
Check Perfect Number?(Option 3)
Enter your option: 3
Integer?6
Perfect Number
----------
5
# Y.Mukul Anand-11A-19-Practical Record File
Exit (Option 0)
Check Armstrong Number?(Option 1)
Check Palindrome Number?(Option 2)
Check Perfect Number?(Option 3)
Enter your option: 3
Integer?34234
Not Perfect Number
----------
Exit (Option 0)
Check Armstrong Number?(Option 1)
Check Palindrome Number?(Option 2)
Check Perfect Number?(Option 3)
Enter your option: 0
'''
#(3)
while True:
print('-'*10)
print('Exit (Option 0)')
print('Check Fibinacci Number?(Option 1)')
print('Check Prime or Composite Number?(Option 2)')
print('Calculate HCF and LCM?(Option 3)')
op=int(input('Enter your option: '))
#Check Fibonacci Number
if op==1:
n=int(input('Enter an integer: '))
t1,t2=0,1
while True:
if t1==n:
print('Fibonacci Number')
break
elif t1>n:
print('Not a Fibonacci Number')
break
t1,t2=t2,t1+t2
if op==2:
#Check Prime Number
n=int(input('Enter an integer: '))
c=0
for i in range(1,n+1):
if n%i==0:
c+=1
if c==2:
print('Prime Number')
else:print('Not Prime Number')
if op==3:
#Calculate HCF and LCM
a=int(input('1st Integer?'))
b=int(input('2nd Integer?'))
p=a*b
while a%b:
a,b=b,a%b
print('HCF=',b)
print('LCM=',p//b)
6
# Y.Mukul Anand-11A-19-Practical Record File
if op==0:
break
'''Sample Output
----------
Exit (Option 0)
Check Fibinacci Number?(Option 1)
Check Prime or Composite Number?(Option 2)
Calculate HCF and LCM?(Option 3)
Enter your option: 1
Enter an integer: 8
Fibonacci Number
----------
Exit (Option 0)
Check Fibinacci Number?(Option 1)
Check Prime or Composite Number?(Option 2)
Calculate HCF and LCM?(Option 3)
Enter your option: 1
Enter an integer: 10
Not a Fibonacci Number
----------
Exit (Option 0)
Check Fibinacci Number?(Option 1)
Check Prime or Composite Number?(Option 2)
Calculate HCF and LCM?(Option 3)
Enter your option: 2
Enter an integer: 2
Prime Number
----------
Exit (Option 0)
Check Fibinacci Number?(Option 1)
Check Prime or Composite Number?(Option 2)
Calculate HCF and LCM?(Option 3)
Enter your option: 2
Enter an integer: 6
Not Prime Number
----------
Exit (Option 0)
Check Fibinacci Number?(Option 1)
Check Prime or Composite Number?(Option 2)
Calculate HCF and LCM?(Option 3)
Enter your option: 3
1st Integer?12
2nd Integer?15
HCF= 3
LCM= 60
----------
Exit (Option 0)
Check Fibinacci Number?(Option 1)
Check Prime or Composite Number?(Option 2)
Calculate HCF and LCM?(Option 3)
Enter your option: 0
'''
#(4)
7
# Y.Mukul Anand-11A-19-Practical Record File
from random import randint
while True:
print('-'*10)
print('Exit (Option 0)')
print('Calculate AM,GM,HM?(Option 1)')
print('Calculate the Sum and Average of values stored in Even and
Odd Index?(Option 2)')
op=int(input('Enter your option: '))
if op==1:
n=int(input('Enter No of Integers: '))
m=[randint(1000,9999)/100 for i in range (n)]
print('LIST =')
for i in m:
print(i,end=' ')
print()
s,p,rs=0,1,0
for i in m:
s+=i
p*=i
rs+=1/i
am=s/n
gm=p**(1/n)
hm=(gm)**2/(am)
print('Arithmatic Mean=',am)
print('Geometric Mean=',gm)
print('Harmonic Mean=',hm)
if op==2:
c1=c2=s1=s2=0
for x in range(n):
if x%2==1:
s1+=m[x]
c1+=1
else:
s2+=m[x]
c2+=1
print('Sum of Edd index elements =',s1)
print('Sum of Even index elements =',s2)
print('Average of Odd index elements =',s1/c1)
print('Average of Even index elements =',s2/c2)
if op==0:
break
'''Sample Output
----------
Exit (Option 0)
Calculate AM,GM,HM?(Option 1)
Calculate the Sum and Average of values stored in Even and Odd Index?
(Option 2)
Enter your option: 1
Enter No of Integers: 7
LIST =
69.82 98.49 82.95 25.51 40.21 82.68 72.52
Arithmatic Mean= 67.4542857142857
Geometric Mean= 61.96634505911189
8
# Y.Mukul Anand-11A-19-Practical Record File
Harmonic Mean= 56.924891863048934
----------
Exit (Option 0)
Calculate AM,GM,HM?(Option 1)
Calculate the Sum and Average of values stored in Even and Odd Index?
(Option 2)
Enter your option: 2
Sum of Edd index elements = 206.68
Sum of Even index elements = 265.5
Average of Odd index elements = 68.89333333333333
Average of Even index elements = 66.375
----------
Exit (Option 0)
Calculate AM,GM,HM?(Option 1)
Calculate the Sum and Average of values stored in Even and Odd Index?
(Option 2)
Enter your option: 0
'''

You might also like