2/19/25, 4:02 PM 352_whileloop2&forloop - Colab
num=int(input('Enter a number:'))
i=1
while i<=10:
print(f"{num} x{i}={i*num}")
i+=1
Enter a number:5
5 x1=5
5 x2=10
5 x3=15
5 x4=20
5 x5=25
5 x6=30
5 x7=35
5 x8=40
5 x9=45
5 x10=50
n=int(input('Enter a number:'))
factorial=1
i=1
while i<=n:
factorial*=i
i+=1
print(f"The factorial of {n} is {factorial}")
Enter a number:14
The factorial of 14 is 87178291200
#program to inverse a number
num=int(input('Enter a number:'))# input from the user
reverse_num=0
while num>0:
digit=num%10 # get the last digit
reverse_num=reverse_num*10+ digit # add it to the reversed number
num=num//10 #remove the last digit from the number
#print(digit)
print(f"Reversed number:{reverse_num}")
Enter a number:63456
Reversed number:65436
#print numbers from 1 to 10
for i in range(1,11):
print(i)
1
2
3
4
5
6
7
8
9
10
#print each character in a string
text=input("Enter a string")
for char in text:
print(char)
Enter a stringanushree
a
n
u
s
h
r
e
e
#print even numbers from 1 to 20
for i in range(2,21,2):
https://colab.research.google.com/drive/1y6W_G8-biwJOUs3kRy9h7TM3SBB-_bHL#scrollTo=1xr3JCIWDLHW 1/3
2/19/25, 4:02 PM 352_whileloop2&forloop - Colab
print(i)
2
4
6
8
10
12
14
16
18
20
#print odd numbers from 1 to 22
for i in range(1,22,1):
print(i)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#sum of first n natural numbers
n=int(input("Enter a number:"))
sum =0
for i in range(1,n+1):
sum+=i
print(f"The sum of first {n} natural numbers is {sum}")
Enter a number:123
The sum of first 123 natural numbers is 7626
#sum of first n natural numbers
n=int(input("Enter a number:"))
pro=1
for i in range(1,n+1):
pro*=i
print(f"Sum of first {n} natural numbers is {pro}")
Enter a number:65
Sum of first 65 natural numbers is 1
Sum of first 65 natural numbers is 2
Sum of first 65 natural numbers is 6
Sum of first 65 natural numbers is 24
Sum of first 65 natural numbers is 120
Sum of first 65 natural numbers is 720
Sum of first 65 natural numbers is 5040
Sum of first 65 natural numbers is 40320
Sum of first 65 natural numbers is 362880
Sum of first 65 natural numbers is 3628800
Sum of first 65 natural numbers is 39916800
Sum of first 65 natural numbers is 479001600
Sum of first 65 natural numbers is 6227020800
Sum of first 65 natural numbers is 87178291200
Sum of first 65 natural numbers is 1307674368000
Sum of first 65 natural numbers is 20922789888000
Sum of first 65 natural numbers is 355687428096000
Sum of first 65 natural numbers is 6402373705728000
Sum of first 65 natural numbers is 121645100408832000
Sum of first 65 natural numbers is 2432902008176640000
Sum of first 65 natural numbers is 51090942171709440000
https://colab.research.google.com/drive/1y6W_G8-biwJOUs3kRy9h7TM3SBB-_bHL#scrollTo=1xr3JCIWDLHW 2/3
2/19/25, 4:02 PM 352_whileloop2&forloop - Colab
Sum of first 65 natural numbers is 1124000727777607680000
Sum of first 65 natural numbers is 25852016738884976640000
Sum of first 65 natural numbers is 620448401733239439360000
Sum of first 65 natural numbers is 15511210043330985984000000
Sum of first 65 natural numbers is 403291461126605635584000000
Sum of first 65 natural numbers is 10888869450418352160768000000
Sum of first 65 natural numbers is 304888344611713860501504000000
Sum of first 65 natural numbers is 8841761993739701954543616000000
Sum of first 65 natural numbers is 265252859812191058636308480000000
Sum of first 65 natural numbers is 8222838654177922817725562880000000
Sum of first 65 natural numbers is 263130836933693530167218012160000000
Sum of first 65 natural numbers is 8683317618811886495518194401280000000
Sum of first 65 natural numbers is 295232799039604140847618609643520000000
Sum of first 65 natural numbers is 10333147966386144929666651337523200000000
Sum of first 65 natural numbers is 371993326789901217467999448150835200000000
Sum of first 65 natural numbers is 13763753091226345046315979581580902400000000
Sum of first 65 natural numbers is 523022617466601111760007224100074291200000000
Sum of first 65 natural numbers is 20397882081197443358640281739902897356800000000
Sum of first 65 natural numbers is 815915283247897734345611269596115894272000000000
Sum of first 65 natural numbers is 33452526613163807108170062053440751665152000000000
Sum of first 65 natural numbers is 1405006117752879898543142606244511569936384000000000
Sum of first 65 natural numbers is 60415263063373835637355132068513997507264512000000000
Sum of first 65 natural numbers is 2658271574788448768043625811014615890319638528000000000
Sum of first 65 natural numbers is 119622220865480194561963161495657715064383733760000000000
Sum of first 65 natural numbers is 5502622159812088949850305428800254892961651752960000000000
Sum of first 65 natural numbers is 258623241511168180642964355153611979969197632389120000000000
Sum of first 65 natural numbers is 12413915592536072670862289047373375038521486354677760000000000
Sum of first 65 natural numbers is 608281864034267560872252163321295376887552831379210240000000000
Sum of first 65 natural numbers is 30414093201713378043612608166064768844377641568960512000000000000
Sum of first 65 natural numbers is 1551118753287382280224243016469303211063259720016986112000000000000
Sum of first 65 natural numbers is 80658175170943878571660636856403766975289505440883277824000000000000
Sum of first 65 natural numbers is 4274883284060025564298013753389399649690343788366813724672000000000000
Sum of first 65 natural numbers is 230843697339241380472092742683027581083278564571807941132288000000000000
Sum of first 65 natural numbers is 12696403353658275925965100847566516959580321051449436762275840000000000000
Sum of first 65 natural numbers is 710998587804863451854045647463724949736497978881168458687447040000000000000
Sum of first 65 natural numbers is 40526919504877216755680601905432322134980384796226602145184481280000000000000
#print multiplication table
num=int(input("Enter a number:"))
for i in range(1,11):
print(f"{num} x {i}= {num*i}")
Enter a number:12
12 x 1= 12
12 x 2= 24
12 x 3= 36
12 x 4= 48
12 x 5= 60
12 x 6= 72
12 x 7= 84
12 x 8= 96
12 x 9= 108
12 x 10= 120
https://colab.research.google.com/drive/1y6W_G8-biwJOUs3kRy9h7TM3SBB-_bHL#scrollTo=1xr3JCIWDLHW 3/3