Imagine we are given a situation in a test :
Ques 8 ) Print all The Numbers from 1 to 100 using Python
How will you answer this ?
U cannot write print so many times !
For that we have a term in Python called loops
There are 2 types :
For loop And While loop
Codes for For loop
for a in range (1,1000):
print(a+1)
Codes for While loop
n = 1
while n <= 100:
print(n)
n=n+1
Thank you
2 Likes
kvk
(Vinod Kumar K)
March 25, 2023, 5:16am
2
Shouldn’t the code be:
for a in range (1,100):
print(a)
1 Like
ad02102001
(Anshuman Das)
March 25, 2023, 6:38am
3
Yes that should be. May be a type error of an extra 0.
1 Like
Yes , this was an error but it is not important u can take any number in the range such as
range (5,50):
range (8,90):
range (x,y):
Suheet
(Suheet Sonawane)
March 25, 2023, 7:19am
5
This method will be perfect for the question asked. This will use the minimum computational power. This has 2 for loops which recursively run till you print 1 to 100.
for x in range(0,10):
for y in range(1, 101):
print(y)
1 Like