【发布时间】:2021-01-23 02:34:03
【问题描述】:
我正在创建一个简单的零钱计算器。但是我不确定为什么我的 while 循环没有检查用户输入。我希望程序只接受 1 到 99 之间的数字。
total = int(input('How much change do you need? '))
while total > 100 and total <= 0:
print('The change must be between 1 cent and 99 cents.')
total = int(input('How much change do you need? '))
def change(total):
print(total//25, 'Quarters')
total = total%25
print(total//10, 'Dimes')
total = total%10
print(total//5, 'Nickels')
total = total%5
print(total//1, 'Pennies')
change(total)
谢谢!
【问题讨论】:
-
应该是
while total > 100 or total <= 0:。谢谢! -
绝对!谢谢!很好很容易修复。
标签: python function while-loop calculator