【发布时间】:2020-09-28 22:04:28
【问题描述】:
我有一个需要完成的程序,但我不知道如何完成。我需要让它使用一个while循环并询问他们是否想订购,一旦他们完成了他们是否想再次订购,然后返回到主代码块。我一点也不擅长这个。这是我现在所拥有的:(编辑:对截图感到抱歉)
order= input('Hi, would you like to order anything? Yes (y), No (n)')
if order == "n":
print("Ok have a nice day")
elif order == "y":
ordering_y = type_of_sandwich = input('What kind of sandwich would you like? Chicken for $5.25 (c), Tofu for $5.75 (t), Beef for $6.25(b)?')
if type_of_sandwich == "c":
print('You chose the chicken sandwich for $5.25')
elif type_of_sandwich == "t":
print ('You chose a tofu for $5.75 sandwich')
elif type_of_sandwich == "b":
print('You chose a beef sandwich for $6.25')
bev = input("Would you like a beverage? Yes (y), No (n)?")
if bev == "n":
print("Ok, thanks for your business, would you like to order again?")
elif bev == "y":
size= input('Small for $1.00 (s), Medium for $1.75 (m), Large for $2.25 (l)?')
if size == "s":
print("You ordered a small beverage for $1.00, would you like to order again?")
elif size == "m":
print("You ordered a Medium beverage for $1.75, would you like to order again?")
elif size == "l":
print("You ordered a large beverage for $2.25, would you like to order again?")
order_again= input('Would you like to order again? Yes (y), No (n)')
while true:
if order_again == "n":
print("Ok, thanks for your business.")
break
elif order_again =="y":
repeat order
【问题讨论】:
-
请将您的代码作为文本粘贴到此处,而不是屏幕截图。
-
欢迎来到 Stack Overflow。为了进一步帮助您,我们需要更多详细信息。请花一些时间阅读How to Ask 和minimal reproducible example,了解如何改进您的问题,以便我们提供您正在寻找的答案。
-
请不要发布代码、数据或 Tracebacks 的图像。将其复制并粘贴为文本,然后将其格式化为代码(选择它并输入
ctrl-k)...Discourage screenshots of code and/or errors -
while True: runCode() ... done = input('Are you finished?') ... if done = 'Yes': break.... else: continue...因此,从您的代码的外观来看,您只需要另一个while True循环。
标签: python loops while-loop iteration