首页 > 解决方案 > 如何重复多个输入,直到得到指定的答案?

问题描述

目前正在执行 csnewbs 扩展任务 1 ( https://www.csnewbs.com/python-extended-task-1 ),我一直在努力处理需要 3 个输入并确认它们是正确的代码的一部分。我有 3 个输入,但仅此而已。

print("Hello there, welcome to Pete Porker")

while True:
    e = int(input("Scotch eggs are 30p each. How many would you like to order?"))
    if e == "":
        continue
    p = int(input("Pork Pies are 80p each. How many would you like to order?"))
    if p == "":
        continue
    q = int(input("Quiche Tarts are £1.40 each. How many would you like to order?"))
    if q == "":
        continue
print("You have ordered",e,"eggs",p,"pies and",q,"quiches.")
order = input("Is this the right order?")
if order == "yes":
    continue
elif order == "no":
    break

最后有一个“继续循环不正确”,我也不知道如何解决这个问题。如果有帮助,则在链接末尾有一个脚本应该运行的图像。提前感谢所有回复:)

标签: python

解决方案


您的缩进已关闭。缩进您的最后一条if/elif语句,使其位于 while 循环中,因为现在您的最后一条continue(and break) 不包含在任何循环中。


推荐阅读