Sunday, 1 December 2019

Python program to print 1 to 10 numbers.

Python program to print 1 to 10 numbers


We can generate a sequence of numbers between 1 to 10 using range() function and for loop.

We can also define the starting, ending and step size as range(start,stop,step size) function parameters. By default step size is 1.

# Python program to print 1 to 10 numbers.

for i in range(1,11):
  print(i, end=' ')

Output of the program

1 2 3 4 5 6 7 8 9 10 

# Python program to print 10 to 1 numbers.

for i in range(10,0,-1):
    print(i, end=' ')

Output of the program

10 9 8 7 6 5 4 3 2 1 

No comments:

Post a Comment