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?
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']
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)
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?
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']
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)