擅长:python、mysql、java
<p>您可以定义一个基于餐价设置的<code>tip</code>变量。在</p>
<pre><code>user = float(input("Please input the cost of the meal "))
tip = 0 # we'll overwrite this
if user > .01 and user < 5.99:
tip = 0.1
elif user > 5.99 and user < 12:
tip = 0.13
# etc, until...
else:
# at this point user should be >= 25.01
tip = 0.22
</code></pre>
<p>然后找到实际的小费“价格”,并将其加到总计中:</p>
^{pr2}$