擅长:python、mysql、java
<p><strong>Python3.x版本</strong></p>
<pre><code>productprice = float(input('Enter price of product'))
if 10.0 <= productprice <= 20.0:
afterDiscount = productprice * 0.80
elif 20.1 <= productprice <= 30.0:
afterDiscount = productprice * 0.70
else:
afterDiscount = productprice
print (afterDiscount)
</code></pre>
<p><strong>Python2.x版本</strong></p>
<pre><code>productprice = float(raw_input('Enter price of product'))
</code></pre>
<p><strong>注意事项</p>
<ol>
<li><p>在Python中,可以检查数字是否在给定的范围内,如下所示。你知道吗</p>
<pre><code>0 < num < 3
</code></pre>
<p>如果它在数学上有效,那么它将返回<code>True</code>,否则返回<code>False</code>。</p></li>
<li><p>拥有<code>else</code>部分总是好的。</p></li>
</ol>