嗨,我是 python 新手,我正在通过制作一个简单的计算器来练习。该程序允许我输入膳食、税收和小费的数值,但在计算时出现此错误:
Traceback (most recent call last):
File "C:/Users/chacha04231991/Desktop/pytuts/mealcost.py", line 5, in <module>
meal = meal + meal * tax
TypeError: can't multiply sequence by non-int of type 'str'
这是代码:
meal = raw_input('Enter meal cost: ')
tax = raw_input('Enter tax price in decimal #: ')
tip = raw_input('Enter tip amount in decimal #: ')
meal = meal + meal * tax
meal = meal + meal * tip
total = meal
print 'your meal total is ', total