Practical Questions
Practical Questions
Question 2 (Factorial):
s=int(input("Enter a number:"))
c=1
for i in range(2,s+1):
c*=i
print("Factorial of",s,"is",c)
Output:
Enter a number:8
Factorial of 8 is 40320
Question 3 (Fibonacci series):
print("*****Fibonacci Series*****")
a=int(input("Enter a range:"))
f=0
s=1
print(f,s,end=" ")
for i in range(2,a):
t=f+s
print(t,end=" ")
f,s=s,t
Output:
Enter a range:10
0 1 1 2 3 5 8 13 21 34
Question 9 (to make a list containing index of even digits from a list):
l=[1,2,3,4,5,6,7,8,9,10]
indexl=[]
for i in range(len(l)):
if l[i]%2==0:
indexl.append(i)
print(indexl)
Output:
[1, 3, 5, 7, 9]
Question 10 (nested dictionary):
d={"Dhoni":{"1st Match":77,"2nd Match":42,"3rd Match":45},
"Virat":{"1st Match":56,"2nd Match":68,"3rd Match":37},
"Rohit":{"1st Match":67,"2nd Match":52,"3rd Match":40}}
for i in d:
print(i)
s=0
for j in d[i]:
print(j,d[i][j])
s+=d[i][j]
print("Total:",s)
print("*"*10)
Output:
Dhoni
1st Match 77
2nd Match 42
3rd Match 45
Total: 164
**********
Virat
1st Match 56
2nd Match 68
3rd Match 37
Total: 161
**********
Rohit
1st Match 67
2nd Match 52
3rd Match 40
Total: 159
**********