下面的代码有什么问题,一直报错“Not all arguments converted during string formatting”:
mealPrice = raw_input ("How much did you pay for your meal?: ")
hst1 = 0.13
hst1 = int(hst1)
totalprice = (float(mealPrice) * hst1)
print "Cost of meal", mealPrice
print "Taxes", hst
print "-------------------------------"
print "Total", totalPrice
最佳答案
首先,您需要做的就是指定税率:
hst1 = 0.13
看起来您正在尝试用该数字创建一个字符串,然后将其转换为一个整数。不要那样做;只需创建一个浮点值并使用它。
其次,raw_input 将返回一个字符串值。在使用之前,您需要将其转换为数字:
mealPrice = float(mealPrice)
在那之后,您的缩进看起来很不对——也许这只是因为您粘贴代码的方式,但您的所有行都应该从同一列开始。
最后,最后一行是“end”——这不是 python 语法,不应该出现在那里。删除那个。
关于Python 语法问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13077327/