Practical Record
Practical Record
while True:
print('1. Count digit, sum and product of digits')
print('2. Count odd digits and even digits')
print('3. Sum of odd digits and even digits')
print('4. Product of odd digits and even digits')
print('0. Exit')
ch=int(input('Choice [0-4]? '))
if ch==0:
break
elif ch==1:
n = int(input('Input a positive integer: '))
c,s,p=0,0,1
original_n = n
while n:
d = n % 10
c+=1
s+=d
p*=d
n//=10
print('Number of digits =', c)
print('Sum of digits =', s)
print('Product of digits =', p)
elif ch==2:
n=int(input('Input a positive integer: '))
ce,co=0,0
while n:
d=n%10
if d%2==0:
ce+=1
else:
co+=1
n//=10
print('Even digits =', ce)
print('Odd digits =', co)
elif ch==3:
n=int(input('Input a positive integer: '))
se,so=0,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)
elif ch == 4:
n=int(input('Input a positive integer: '))
pe,po=1,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)
'''Sample Output
1. Count digit, sum and product of digits
2. Count odd digits and even digits
3. Sum of odd digits and even digits
4. Product of odd digits and even digits
0. Exit
Choice [0-4]? 1
Input a positive integer: 123456
Number of digits = 6
Sum of digits = 21
Product of digits = 720
1. Count digit, sum and product of digits
2. Count odd digits and even digits
3. Sum of odd digits and even digits
4. Product of odd digits and even digits
0. Exit
Choice [0-4]? 2
Input a positive integer: 654321
Even digits = 3
Odd digits = 3
1. Count digit, sum and product of digits
2. Count odd digits and even digits
3. Sum of odd digits and even digits
4. Product of odd digits and even digits
0. Exit
Choice [0-4]? 3
Input a positive integer: 765678
Sum of even digits = 20
Sum of odd digits = 19
1. Count digit, sum and product of digits
2. Count odd digits and even digits
3. Sum of odd digits and even digits
4. Product of odd digits and even digits
0. Exit
Choice [0-4]? 4
Input a positive integer: 986034
Product of even digits = 0
Product of odd digits = 27
1. Count digit, sum and product of digits
2. Count odd digits and even digits
3. Sum of odd digits and even digits
4. Product of odd digits and even digits
0. Exit
Choice [0-4]? 0
'''
#4 Mukul Anand Practical Record
from random import randint
alist = False
m = []
while True:
print('-' * 10)
print('Exit (Option 0)')
print('List created with random values (Option 1)')
print('Displaying the created List (Option 2)')
print('Calculate AM, GM, HM (Option 3)')
print('Calculate the Sum and Average of values stored in
Even and Odd Index (Option 4)')
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)]
alist = True
print('List created with random values')
elif op == 2:
if alist:
for x in m:
print(x, end=' ')
print()
else:
print('No List is created')
elif op == 3:
if alist:
s = 0
p = 1
rs = 0
for i in m:
s+=i
p*=i
rs+=1/i
am = s/n
gm = p**(1/n)
hm = n/rs
print('Arithmetic Mean =', am)
print('Geometric Mean =', gm)
print('Harmonic Mean =', hm)
else:
print('No List is created')
elif op == 4:
if alist:
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 Odd 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)
else:
print('No List is created')
elif op == 0:
print("Exiting the program.")
break
'''Sample Output
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Calculate AM, GM, HM (Option 3)
Calculate the Sum and Average of values stored in Even and Odd
Index (Option 4)
Enter your option: 1
Enter No of Integers: 5
List created with random values
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Calculate AM, GM, HM (Option 3)
Calculate the Sum and Average of values stored in Even and Odd
Index (Option 4)
Enter your option: 2
87.47 18.34 32.71 39.12 76.58
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Calculate AM, GM, HM (Option 3)
Calculate the Sum and Average of values stored in Even and Odd
Index (Option 4)
Enter your option: 3
Arithmetic Mean = 50.84400000000001
Geometric Mean = 43.580342796780116
Harmonic Mean = 36.995815275710726
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Calculate AM, GM, HM (Option 3)
Calculate the Sum and Average of values stored in Even and Odd
Index (Option 4)
Enter your option: 4
Sum of Odd index elements = 57.459999999999994
Sum of Even index elements = 196.76
Average of Odd index elements = 28.729999999999997
Average of Even index elements = 65.58666666666666
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Calculate AM, GM, HM (Option 3)
Calculate the Sum and Average of values stored in Even and Odd
Index (Option 4)
Enter your option: 0
Exiting the program.
'''
#5 Mukul Anand Practical Record
from random import *
alist=False
while True:
print('-' * 10)
print('Exit (Option 0)')
print('List created with random values (Option 1)')
print('Displaying the created List (Option 2)')
print('Counting and displaying the number of 3,4,5 digit
numbers and their sum(Option3)')
print('Displaying the Maximum and Minimum value and the
position in the Liast(Option 4)')
op=int(input('Enter your Option :- '))
if op==1:
n=int(input('Enter number of elements in the List :-
'))
blist=[randint(100,99999)for x in range(n)]
alist=True
print('List created with random values')
if op==2:
if alist:
for x in blist: print(x, end=' ')
print()
else: print('No List is created')
elif op==3:
if alist:
c3=c4=c5=s3=s4=s5=0
for x in blist:
if 100<=x<=999:
s3+=x
c3+=1
print('3-Digit Number =',x)
elif 1000<=x<=9999:
s4+=x
c4+=1
print("4-Digit Number =",x)
elif 10000<=x<=99999:
s5+=x
c5+=1
print("5-Digit Number =",x)
print('Sum of 3 Digit Numbers in the List = ', s3)
print('Sum of 4 Digit Numbers in the List = ', s4)
print('Sum of 5 Digit Numbers in the List = ', s5)
print('Number of 3 Digit Numbers in the List = ',
c3)
print('Number of 4 Digit Numbers in the List = ',
c4)
print('Number of 5 Digit Numbers in the List = ',
c5)
else: print('No List is created')
elif op==4:
if alist:
hi=lo=blist[0]
ph=pl=0
for k in range(1, n):
if hi>blist[k]:
hi=blist[k]
ph=k
elif lo<blist[k]:
lo=blist[k]
pl=k
print('Highest Element in the List= ', hi,
'Position= ', ph)
print('Lowest Elemnet in the List= ', lo,
'Position= ', pl)
else: print('No List is created')
elif op==0:
break
'''Sample Output
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Counting and displaying the number of 3,4,5 digit numbers and
their sum(Option3)
Displaying the Maximum and Minimum value and the position in
the Liast(Option 4)
Enter your Option :- 1
Enter number of elements in the List :- 5
List created with random values
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Counting and displaying the number of 3,4,5 digit numbers and
their sum(Option3)
Displaying the Maximum and Minimum value and the position in
the Liast(Option 4)
Enter your Option :- 2
45525 17585 16756 25036 70047
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Counting and displaying the number of 3,4,5 digit numbers and
their sum(Option3)
Displaying the Maximum and Minimum value and the position in
the Liast(Option 4)
Enter your Option :- 3
5-Digit Number = 45525
5-Digit Number = 17585
5-Digit Number = 16756
5-Digit Number = 25036
5-Digit Number = 70047
Sum of 3 Digit Numbers in the List = 0
Sum of 4 Digit Numbers in the List = 0
Sum of 5 Digit Numbers in the List = 174949
Number of 3 Digit Numbers in the List = 0
Number of 4 Digit Numbers in the List = 0
Number of 5 Digit Numbers in the List = 5
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Counting and displaying the number of 3,4,5 digit numbers and
their sum(Option3)
Displaying the Maximum and Minimum value and the position in
the Liast(Option 4)
Enter your Option :- 4
Highest Element in the List= 16756 Position= 2
Lowest Elemnet in the List= 70047 Position= 4
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Counting and displaying the number of 3,4,5 digit numbers and
their sum(Option3)
Displaying the Maximum and Minimum value and the position in
the Liast(Option 4)
Enter your Option :- 0
'''
#6 Mukul Anand Practical Record
from random import *
alist=False
while True:
print('-' * 10)
print('Exit (Option 0)')
print('List created with random values (Option 1)')
print('Displaying the created List (Option 2)')
print('Calculating The Sum of Digits present in the
list(Option 3)')
print('Calculating The Sum and average of odd and even
integers(Option 4)')
print('Exit(Option 0)')
op=int(input('Enter your Option:- '))
if op==1:
n=int(input('Enter No. of elements :- '))
blist=[randint(1000, 9999)for x in range(n)]
alist=True
print('List created with random values')
elif op==2:
if alist:
for x in blist: print(x, end=' ')
print()
else: print('No List is created')
elif op==3:
if alist:
s=0
for x in blist:
while x:
d=x%10
s+=d
x//=10
print("Sum of Digits of inteegers present in List
= ", s)
else: print('No List is created')
elif op==4:
if alist:
s1=s2=c1=c2=0
for x in blist:
if x%2==1:
s1+=x
c1+=1
else:
s2+=x
c2+=1
print("Sum of Even Digits: ", s2)
print("Sum of Odd Digits: ", s1)
print("Average of even Digits: ", s2/c2)
print("Average the number of Odd Digits: ", s1/c1)
else: print('No List is created')
elif op==0:
break
'''Sample Output
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Calculating The Sum of Digits present in the list(Option 3)
Calculating The Sum and average of odd and even
integers(Option 4)
Exit(Option 0)
Enter your Option:- 1
Enter No. of elements :- 5
List created with random values
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Calculating The Sum of Digits present in the list(Option 3)
Calculating The Sum and average of odd and even
integers(Option 4)
Exit(Option 0)
Enter your Option:- 2
7662 8401 5527 3443 5711
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Calculating The Sum of Digits present in the list(Option 3)
Calculating The Sum and average of odd and even
integers(Option 4)
Exit(Option 0)
Enter your Option:- 3
Sum of Digits of inteegers present in List = 81
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Calculating The Sum of Digits present in the list(Option 3)
Calculating The Sum and average of odd and even
integers(Option 4)
Exit(Option 0)
Enter your Option:- 4
Sum of Even Digits: 7662
Sum of Odd Digits: 23082
Average of even Digits: 7662.0
Average the number of Odd Digits: 5770.5
----------
Exit (Option 0)
List created with random values (Option 1)
Displaying the created List (Option 2)
Calculating The Sum of Digits present in the list(Option 3)
Calculating The Sum and average of odd and even
integers(Option 4)
Exit(Option 0)
Enter your Option:- 0 '''
1. Create a Dictionary
2. Show dictionary
3. Maximum, Average Mark, Lowest Mark
4. No of A1, A2 Grades
0. Exit
Enter the option number [0-4] ? 1
Enter roll: 1
Enter name: AAA
Enter marks: 80
Enter grade: B1
Enter roll: 2
Enter name: BBB
Enter marks: 85
Enter grade: A2
Enter roll: 3
Enter name: CCC
Enter marks: 9
Enter grade: F
Enter roll: 4
Enter name: DDD
Enter marks: 99
Enter grade: A1
Enter roll: 5
Enter name: EEE
Enter marks: 78
Enter grade: B2
Enter roll: 6
Enter name: FFF
Enter marks: 94
Enter grade: A1
Enter roll: 7
Enter name: GGG
Enter marks: 63
Enter grade: C1
Enter roll: 8
Enter name: HHH
Enter marks: 89
Enter grade: A2
Enter roll: 9
Enter name: III
Enter marks: 91
Enter grade: A1
Enter roll: 10
Enter name: JJJ
Enter marks: 97
Enter grade: A1
1. Create a Dictionary
2. Show dictionary
3. Maximum, Average Mark, Lowest Mark
4. No of A1, A2 Grades
0. Exit
Enter the option number [0-4] ? 2
{1: ['AAA', 80, 'B1'], 2: ['BBB', 85, 'A2'], 3: ['CCC', 9,
'F'], 4: ['DDD', 99, 'A1'], 5: ['EEE', 78, 'B2'], 6: ['FFF',
94, 'A1'], 7: ['GGG', 63, 'C1'], 8: ['HHH', 89, 'A2'], 9:
['III', 91, 'A1'], 10: ['JJJ', 97, 'A1']}
1. Create a Dictionary
2. Show dictionary
3. Maximum, Average Mark, Lowest Mark
4. No of A1, A2 Grades
0. Exit
Enter the option number [0-4] ? 3
Highest marks: 99
Lowest marks: 9
Average marks: 78.5
1. Create a Dictionary
2. Show dictionary
3. Maximum, Average Mark, Lowest Mark
4. No of A1, A2 Grades
0. Exit
Enter the option number [0-4] ? 4
No of A1: 4
No of A2: 2
1. Create a Dictionary
2. Show dictionary
3. Maximum, Average Mark, Lowest Mark
4. No of A1, A2 Grades
0. Exit
Enter the option number [0-4] ? 0