python跳回循环开始位置_如何将程序从用户输入循环回起始位置?

我刚刚开始使用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.')

我如何添加一个循环,在某个输入时重新启动程序?

谢谢!

-便盆

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值