Reputation: 1014
I'm very beginner of programming.
I'm trying to make program which is able to input 10 numbers.
Therefore I could make this kind of program:
while True:
s = input('Enter 10 numbers : ')
if len(s) == 10:
break
else:
print('Retype your 10 personal numbers!!')
print('Done')
However, I want to input numbers into array like s[10]
?
For instance, if I input '1234567890'
, it is input like s[0]=1
, s[1]=2
,...,s[10]=0
.
Please enlighten me on the specifics.
Upvotes: 1
Views: 644
Reputation: 492
or you can just make a simple update in your program i.e just declare s as the empty list first. It is :
s=[]
while True:
s = input('Enter 10 numbers : ')
if len(s) == 10:
break
else:
print('Retype your 10 personal numbers!!')
print('Done')
Upvotes: 0
Reputation: 140178
if s='1234567890'
then you can turn s
into a list of digits with a simple list comprehension:
s = [int(d) for d in s]
then
>>> s
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
>>> s[9]
0
(s[10]
is out of range BTW :))
Upvotes: 4