python - 如何重复多个输入,直到得到指定的答案?
问题描述
目前正在执行 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
最后有一个“继续循环不正确”,我也不知道如何解决这个问题。如果有帮助,则在链接末尾有一个脚本应该运行的图像。提前感谢所有回复:)
解决方案
您的缩进已关闭。缩进您的最后一条if/elif
语句,使其位于 while 循环中,因为现在您的最后一条continue
(and break
) 不包含在任何循环中。
推荐阅读
- networking - TAP 设备上是否可以使用除以太网之外的其他第 2 层协议?
- spring - ManyToMany 双向级联,保存一侧(拥有方)的作品,但不保存另一侧
- javascript - 如何在 React-Native 中使用 fetch 在 ComponentDidMount 中执行多个 API 调用?
- firebase - TypeError: undefined is not an object (评估'const.join')
- angular - 无法解析相对于“”Angular 7 的模块“”
- java - 如何通过 URI 模板和 HttpMethod 解析 Micronaut 控制器方法?
- database - 我需要从 YugaByte DB 中的本地主机运行什么凭据?
- python - SFTP 连接失败 socket.timeout?
- php - 如何在php中将unix时间戳转换为cet时间?
- javascript - 如何在 ReactJS 中获取 contentEditable 输入的初始值和 setState 值?