擅长:python、mysql、java
<p>我建议的唯一改进是使用<code>format</code>-函数而不是字符串连接:</p>
<pre><code>print """The total price for {0:d} books including shipping and discount is:
Total price of the books is: {1:7.2f}
Total Shipping is: {2:7.2f}
The Total price is: {3:7.2f}""".format(totalUnits, bookDiscountAmount
shipping, result)
</code></pre>
<p>这使得所有的数字都很好地对齐并且格式相同(小数点后有两位数字,总精度为7)。</p>
<p><strong>编辑:</strong>当然,正如其他人指出的,不要硬编码那里的<code>59</code>。</p>