def main():
#this is the part that I want to restart after the total is given
print("Welcome to static burger!")
print("Please answer each question with y or n.")
#The bill and food variables
bill = 0.00
hb = 8.00
cb = 6.00
cs = 5.00
fry = 2.00
cdmts = 1.00
#The code adds up the user's order than prints his/her total.
first = (input("Would you like a hamburger?"))
if first == 'y':
(input('with cheese?'))
if first == 'y':
bill = (hb 2.00)
else:
bill = hb
second = (input("Would you like a cheeseburger?"))
if second == 'y':
bill = cb
third = (input("Would you like a chicken sandwich?"))
if third == 'y':
bill = cs
fourth = (input("Would you like a fries?"))
if fourth == 'y':
bill = fry
fifth = (input("Would you like condiments?"))
if fifth == 'y':
bill = cdmts
else:
bill = bill
tip = 1.2
total = bill * tip
bill * 0.2
#total of the users order
print("Your total is $" "{:.2f}".format(total), "dollars")
#在列印出這個thankyou之后,我希望代碼重新啟動,就好像一個新人正在下訂單一樣。print("感謝您的光臨!") main()
#TLDR 我只想知道使用哪個回圈來讓我不斷重啟并讓用戶選擇新專案并獲得新的總數。
uj5u.com熱心網友回復:
while True:從您希望代碼重復的位置添加一條陳述句。
def main():
#this is the part that I want to restart after the total is given
print("Welcome to static burger!")
print("Please answer each question with y or n.")
#The bill and food variables
bill = 0.00
hb = 8.00
cb = 6.00
cs = 5.00
fry = 2.00
cdmts = 1.00
#The code adds up the user's order than prints his/her total.
while True:
first = (input("Would you like a hamburger?"))
if first == 'y':
(input('with cheese?'))
if first == 'y':
bill = (hb 2.00)
else:
bill = hb
second = (input("Would you like a cheeseburger?"))
if second == 'y':
bill = cb
third = (input("Would you like a chicken sandwich?"))
if third == 'y':
bill = cs
fourth = (input("Would you like a fries?"))
if fourth == 'y':
bill = fry
fifth = (input("Would you like condiments?"))
if fifth == 'y':
bill = cdmts
else:
bill = bill
tip = 1.2
total = bill * tip
bill * 0.2
#total of the users order
print("Your total is $" "{:.2f}".format(total), "dollars")
print()
main()
對于break回圈,您可以添加一個條件并使用該break陳述句。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/511130.html
上一篇:day08-MySQL事務
下一篇:R中多列的If陳述句
