vertopal.com_Python Lab Assignment_ 3 Loops
vertopal.com_Python Lab Assignment_ 3 Loops
1. Write a python program that displays odd/ even numbers less that 20
for i in range (0,20,2):
print(i,end=', ')
for i in range(1,20,2):
print(i, end= ", ")
print("odd\t\teven")
for i in range(1,20):
print(i+2, "\t\t",i)
odd even
3 1
4 2
5 3
6 4
7 5
8 6
9 7
10 8
11 9
12 10
13 11
14 12
15 13
16 14
17 15
18 16
19 17
20 18
21 19
2. Write a program that computes and displays the sum of odd/even numbers less
than 20
Sum=0
for j in range (1,20,2):
Sum=Sum+j
print("Sum = ",Sum)
Sum = 100
3. Write a program that computes the factorial of a number provided as an input
The factorial of 98 is
9426890448883247745626185743057242473809693764078951663494238777294707
0700232237988829761592077291198236058505886084604294126475673600000000
00000000000000
4. Write a program that computes the HCF of two numbers provided as an input
num1= int(input(" Enter ist number for the HCF : "))
num2= int(input(" Enter 2nd number for HCF:"))
if num1<num2:
smaller=num1
else :
smaller=num2
hcf=1
for i in range (2, smaller+1,1):
if ((num1%i==0) and (num2%i==0)):
hcf=i
print(" HCF is", hcf)
HCF is 1
4. Problems from the book
total_bugs=0
for i in range(1,6):
bugs= int(input(f"Enter the num of bugs collected each day
{i} :"))
total_bugs += bugs
print("Total num of bugs in 5 days : ", total_bugs)
fee= 8000
percent_increase=3
for i in range(1,6):
tution+= (fee*3)/100+fee
print(f"the tution in year {i} :", tution)
The factorial of 3 is 6
Enter a number for the factorial: 5
Nested Loops
1. Draw the star pattern