Can I make a list with multi-digit numbers?

Question:

I cannot seem to make a list from an input and not have that list separate any multi-digit numbers into individual numbers. e.g. 100 becomes 1, 0, 0, 284 becomes 2, 8, 4, and so on.

data = list(input("What is your data? must be numbers separated by spacesn"))
print(data)

If I entered my data as: 1 2 3 100, it would print as 1, 2, 3, 1, 0, 0. Is there any way I can have it instead be 1, 2, 3, 100?

Asked By: baxtermaia5000

||

Answers:

You could do this,

In [1]:  input("What is your data? must be numbers separated by spacesn").split(' ')
What is your data? must be numbers separated by spaces
1 2 3 100
Out[1]: ['1', '2', '3', '100']
Answered By: Rahul K P

You should split your input before putting it in a list.

And probably, you want to convert the strings to integers.

Something like:

s = input().split(" ") 
data = [int(x) for x in s] 
print(data) 
Answered By: user107511
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.