擅长:python、mysql、java
<p>问题是:</p>
<pre><code>"Sales Amount: " + userQuantityPurchased + userPrice
</code></pre>
<p>您有一个字符串,您正试图向其中添加一个数字。<code>+</code>运算符可以将字符串连接在一起,但不会自动将数字连接到字符串。您必须将数字量转换为字符串才能将其串联:</p>
<pre><code>"Sales Amount: " + str(userQuantityPurchased + userPrice)
</code></pre>
<p>虽然基于变量名,但您似乎希望实际将<em>乘以</em><code>userPrice</code>乘以<code>userQuantityPurchased</code>,这样总金额将等于所有购买物品的总成本:</p>
<pre><code>"Sales Amount: " + str(userQuantityPurchased * userPrice)
</code></pre>