目前正在执行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
最后有一个“continue not property in loop”,我也不知道如何解决这个问题。如果有帮助的话,在链接的末尾有一个脚本应该运行的图像。提前感谢所有回复:)
如果break==no,则需要继续,否则需要break(因此这与您所做的相反)。您的最后一个if-then-else语句没有正确识别(它应该是再向右一级)。您也无法检查整数是否==“”
另外,如果输入的金额为空,我不会循环整个循环。。。我会写一个简单的函数,它有一个内部循环,不断地问相同的问题,直到得到任何非空的答案。。。差不多
然后你的主循环看起来像
你的缩进消失了。缩进最后一个
if/elif
语句,使其位于while循环中,因为现在最后一个continue
(和break
)不包含在任何循环中相关问题 更多 >
编程相关推荐