Q:

Python | Demonstrate an example of for loop

0

Example:

Here, we are running loop for given ranges with various arguments like argument 1,2,3 and reverse order of the loop.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

print("Type 1")
for i in range(10):  # start=0 , end=10,step=1
    print(i,end="  ")

print("\nType 2")
for i in range(1,11):  # start=1 , end=10,step=1
    print(i,end="  ")

print("\nType 3")
for i in range(1,11,3):  # start=1 , end=10,step=3
    print(i,end="  ")
    
print("\nType 4")
for i in range(10,0,-1):  # start=10 , end=0,step=-1
    print(i,end="  ")

Output

Type 1
0  1  2  3  4  5  6  7  8  9
Type 2
1  2  3  4  5  6  7  8  9  10
Type 3
1  4  7  10
Type 4
10  9  8  7  6  5  4  3  2  1

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now