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=' ')
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=' ')
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)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.