【发布时间】:2021-05-07 09:19:08
【问题描述】:
这里是初学者。我正在尝试构建一个循环,其中 chekout 显示的总金额必须超过 0 美元。例如,如果我从 450$ 开始,则代码有效。但是如果我从 -12 开始,它会再次询问我(这就是我想要的),但是如果我输入 450 作为第三篇文章;第一个条件继续运行。这是为什么?提前致谢。
amount = input("What's the total amount of the bill ? :")
value = float(amount)
while (value < 0):
print("Please enter an amount higher than 0$ !")
amount = input("What's the total amount of the bill ? :")
else:
print("Total amount of the bill:{0}".format(value))
【问题讨论】:
-
while..else不是你想象的那样。此外,您永远不会在while循环内更新value。
标签: python loops while-loop conditional-statements