Print Numbers From 1 to 10 in Python

In this post, we will discuss how to print numbers from 1 to 10 in python using for loop and while loop. Also, develop a program to print 1 to 10 without loop in python.

We will take a range from 1 to 11. Then, print all numbers in an interval 1 to 11 using the For Loop.

Program description:- Write a program to print numbers from 1 to 10 using for loop in python

# Python program to print numbers from 1 to 10

print('Numbers from 1 to 10:')
for n in range(1, 11):
   print(n, end=' ')

Output:-

Numbers from 1 to 10:
1 2 3 4 5 6 7 8 9 10

In the previous program, we used for loop to print 1 to 10 but In this program, we are using the while loop to print 1 to 10 numbers.

Program description:- Python program to print numbers from 1 to 10 using while loop

# Python program to print numbers from 1 to 10

print('Numbers from 1 to 10:')
n = 1
while n <= 10:
   print(n, end=' ')
   n = n+1

Output:-

Numbers from 1 to 10:
1 2 3 4 5 6 7 8 9 10

This python program also performs the same task but in this program, we print 1 to 10 without the loop. To solve this problem, we can use recursion techniques.

A method that contains a call to itself is called the recursive method. A technique of defining the recursive method is called recursion. The recursive method allows us to divide the complex problem into identical single simple cases that can be handled easily. This is also a well-known computer programming technique: divide and conquer.

# Python program to print numbers from 1 to 10

def print_num(n):
   if n > 0:
      print_num(n - 1)
      print(n, end = ' ')

print('Numbers from 1 to 10:')
print_num(10)

Output:-

Numbers from 1 to 10:
1 2 3 4 5 6 7 8 9 10

Get notes to make your learning process easy. These are specially designed for beginners who want to learn coding through simple words, programs, and examples. You can use it as your reference and for revision purposes.

Notes Available:- Python, Java, C/C++, DSA, SQL, HTML CSS JavaScript, etc…

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *