我刚刚开始使用python。我做的第一个程序是一个提示计算器,我已经做了三个版本来重写和添加更多。我想编写的下一部分代码是一个循环,它提示一个是或否问题。当“是”时,我希望程序循环到最开始的时候;当“否”时,我希望程序退出;当出现无效命令时,我希望程序打印(“无效命令”),并继续等待“是”或“否”。代码如下:print('Good evening sir, I am Tippos! Please, tell me the price of your meal and how much you would like to tip and I\'ll do the math for you!')
bill_amt = input('First sir, what was the price of your meal?(Please do not use signs such as "$"):')
tax = 1.13
x = float(bill_amt)
tip_amt = input('And how much would you like to tip? 10, 15, or maybe 20% Go on, any number sir!(Please do not use signs such as "%"):')
y = float(tip_amt)
tip_amt = x * (y / 100)
print('Your tip will cost you an extra' ,tip_amt, 'dollars.')
total_amt = (x + y) * tax
print('Your total cost will be' ,total_amt, 'dollars, sir.')
我如何添加一个循环,在某个输入时重新启动程序?
谢谢!
-便盆