我试图在课堂上为一个项目编写一个计算器,但一直遇到错误:
追踪(最近一次通话): 文件" C:\ Users \ shane \ PythonPrograms \ louie.py",第56行,in tax_percent =(价格*税) TypeError:不能将序列乘以非int类型' float'
我的代码如下。任何人都可以帮我调试吗?
size_types = {'mini',
'regular',
'large'
}
meat_types = {'pork',
'beef',
'chicken'
}
def price_pork_meal(size):
if size == 'mini':
return 3.00
if size == 'regurlar':
return 4.00
if size == 'large':
return 6.00
else:
return (input('Please try again:'))
return size
def price_beef_meal(size):
if size == 'mini':
return 4.00
if size == 'regular':
return 7.00
if size == 'large':
return 9.00
else:
return (input('Please try again:'))
return size
def price_chicken_meal(size):
if size == 'mini':
return 3.50
if size == 'regular':
return 6.00
if size == 'large':
return 8.00
else:
return (input('Please try again:'))
return size
def final_price(price, tax_percent):
price = size
total_price = price + tax_percent
return total_price
size = (input('Please enter mini, regular, or large:\n'))
price = size
tax = 0.825
tax_percent = (price * tax)
print(final_price(price, tax_percent))
答案 0 :(得分:1)
您的方法在python中无效。您不能将序列与浮点值相乘,如错误中所写。
这不会起作用:
a = (1,2,3)
b = a * 0.25
您可以使用支持此功能的numpy(以及更多功能)或自行实现:
a = (1,2,3)
b = list(map(lambda x: x*0.2, a)) # or many other approaches; outer list needed in python3 to make it a list instead of an generator-expression