如果输入2位或更多位数,我希望我的程序说'无效输入',那么有没有办法将我的用户输入限制在python中的单个数字?如何限制我的用户输入为单个数字? (Python)
这是我的代码:
print('List Maker')
tryagain = ""
while 'no' not in tryagain:
list = []
for x in range(0,10):
number = int(input("Enter a number: "))
list.append(number)
print('The sum of the list is ',sum(list))
print('The product of the list is ',sum(list)/float(len(list)))
print('The minimum value of the list is ',min(list))
print('The maximum vlaue of the list is ',max(list))
print(' ')
tryagain = input('Would you like to restart? ').lower()
if 'no' in tryagain:
break
print('Goodbye')
如果数> 9或数<-9 –
替代地,而数<= 9和编号> = - 9 –