Loops In Python

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):

Codes for While loop

n = 1
while n <= 100:

Thank you


Shouldn’t the code be:

for a in range (1,100):
1 Like

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):

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):

1 Like