I want to get a list of numbers as input from the user dynamically

Submitted 4 years, 6 months ago
Ticket #217
Views 351
Language/Framework Python
Priority Medium
Status Closed

Suggest me a way to take list of numbers as input 

Help from anyone will make me solve it more easily

Submitted on Oct 07, 20
sai
add a comment

3 Answers

lines = []
while True:
  line = list(map(int,input().split()))
  if line:
    lines.append(line)
  else:
    break
print(lines)

Submitted 4 years, 6 months ago

numberList = []
n = int(input("Enter the list size : "))

print("\n")

for i in range(0, n):
    print("Enter number at location", i, ":")
    item = int(input())
    numberList.append(item)
print("User List is ", numberList)

output

Enter the list size : 3


Enter number at location 0 :
3
Enter number at location 1 :
4
Enter number at location 2 :
5
User List is  [3, 4, 5]

Submitted 4 years, 6 months ago


Verified

print("enter any no of numbers")
a = [int(x) for x in input().split()]

print("numbers are",a)

Output will be:

enter any no of numbers

1 2 3 4 5 6 7
numbers are [1, 2, 3, 4, 5, 6, 7]

Submitted 4 years, 6 months ago


Latest Blogs