编写一个程序,要求用户输入他们可以做的俯卧撑数量。程序应强制用户通过重复问题输入有效数字,直到输入0到500之间的数字。一旦提供了有效的答案,该程序应该打印出来:“Wimp !!我可以做X.“其中X是用户输入的内容之一。
这是shell显示的内容:
How many push-ups can you do? 1000
Liar, please enter a number between 0 and 500: 2341
Liar, please enter a number between 0 and 500: 75
Wimp!! I can do 76.
答案 0 :(得分:-1)
这应该做的工作:
while True:
answer = int(input("How many push ups can you do?\n"))
if answer > 500 or answer < 0:
print("Liar, please enter a number between 0 and 500:")
continue
else:
print("Wimp!! I can do {x}.".format(x = answer + 1))
break