【发布时间】:2016-09-26 13:46:00
【问题描述】:
如果输入了 2 位或更多位,我希望我的程序说“无效输入”,那么有没有办法在 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
标签: python