Print n numbers in Python using for loop | Example code

  • by

Iterate for loop with the given number to print n numbers in Python using for loop.

Print n numbers in Python using for loop

Simple example code print first n numbers in Python. First, initialize a variable “numbers” with the number of numbers you want to print. Then use for loop and print the values.

numbers = 10

for num in range(1, numbers + 1):
    print(num, end=' ')

Output:

Print n numbers in Python using for loop

Print numbers from 1 to N using the input function

With the input() function you can take e user input value.

n = int(input("Please Enter any Number: "))

print("The List of Natural Numbers from 1", "to", n)

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

Output:

Please Enter any Number: 5
The List of Natural Numbers from 1 to 5
1 2 3 4 5

Do comment if you have any doubts or suggestions on this Python number topic.

Note: IDE: PyCharm 2021.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.