How to Print N numbers in a List in Python

Here is a Python program that prints N numbers. It asks input from the user how many numbers to print. The user input is used in the if condition to print the numbers.

Here is sample Python program

nums= []
# number of elements as input
n = int(input("Enter number of elements : "))
# iterating till the range
for i in range(0, n):
ele = int(input("Enter number:"))
nums.append(ele) # adding the element


Also read: 12 Tricky Python Coding Interview Questions

The result of the program

Enter number of elements : 
Enter number:
Enter number:
Enter number:
Enter number:
Enter number:
[1, 2, 3, 4, 5]

** Process exited - Return Code: 0 **
Press Enter to exit terminal

Related posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.