userInput = []
for i in xrange(1, 10):
userInput.append(raw_input('Enter the %s number: '))
userInput = ''
while len(userInput) != 1:
userInput = raw_input(':')
guessInLower = userInput.lower()
print"the numbers you have entered are: ", userInput
所以我试图制作一个程序,它需要10个单位输入,然后将它们放入一个单独的字符串然后在它输入10个单位数字输入之后它然后打印出我已经得到的所有单个数字输入但是我无法找到先检查的方法。有什么建议吗?
答案 0 :(得分:0)
根据您的意思,以下代码是您想要的:
userInput = ""
for i in xrange(1, 11):
userInput += (raw_input('Enter the %s number: '))
print"the numbers you have entered are: ", userInput
Enter the %s number: 1
Enter the %s number: 2
Enter the %s number: 3
Enter the %s number: 4
Enter the %s number: 5
Enter the %s number: 6
Enter the %s number: 7
Enter the %s number: 8
Enter the %s number: 9
Enter the %s number: 0
the numbers you have entered are: 1234567890
答案 1 :(得分:0)
你应该将它全部放在一个循环中并检查输入是否是一个数字:
user_inp = ""
while len(user_inp) < 10:
inp = raw_input("Enter a digit")
if len(inp) == 1 and inp.isdigit(): # check length and make sure a digit is entered
user_inp += inp
else:
print("Invalid input")
print("The numbers you have entered are: {}".format(user_inp))