<p>运行这个有点麻烦。基本上,我只想得到一个数额,如果它超过50免费送货和少于10美元额外收费。我一直收到一个关于将浮点转换为str隐式的错误?我认为我的输入应该被视为浮动?在</p>
<pre><code>#declare flags
shippingCharge = 10
freeShipping = False
#Get number and convert to float?
purchaseAmount = float(input("\nHow much is the purchase amount? "))
if (purchaseAmount) >= 50 :
freeShipping = True
print("Your purchase amount is " + purchaseAmount + "$ and shipping is free!")
else :
print("Your purchase amount is " + purchaseAmount + "$ and shipping is " + shippingCharge + "$.")
purchaseAmount = shippingCharge + purchaseAmount
print("Your new total is " + purchaseAmount)
print ("Have a nice day and thank you for shopping with us.")
</code></pre>
<p>只需将purchaseAmount替换为str(purchaseAmount),就可以了。在</p>
<pre><code>How much is the purchase amount? 50
Your purchase amount is 50.0$ and shipping is free!
Have a nice day and thank you for shopping with us.
</code></pre>