![](/img/trans.png)
[英]TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'
[英]Python - TypeError: unsupported operand type(s) for +: 'int' and 'NoneType"
這是我的第一門編程課,我很難解決這個問題。 我似乎無法使它正常工作,我不斷收到“ TypeError:+不支持的操作數類型:'int'和'NoneType”
def woodtype(wood):
MAH=float(75.00)
OAK=float(100)
coffetab=float(0)
if woodtype=="mahogany":
coffetab=MAH
else:
if woodtype=="oak":
coffetab=OAK
lamp=65
tables=155
print("the cost per desk lamp is $%.2f" %lamp)
print("the cost per coffee table is $%.2f" %tables)
dl=input("how many desk lamps are you buying?:")
desklamps=int(dl)
cf=input("how many coffee tables are you buying?:")
coffeetables=int(cf)
print("what type of wood would you like the coffee tables; mahogany, oak or pine.")
wood=input("what type of wood for your coffee tables?:")
costofwood=woodtype(wood)
total= (desklamps*65)+(coffeetables*(15+costofwood))
print("the total cost of your purchase is $%.2f" %total)
您的函數woodtype
似乎縮進得很差,並且沒有return語句,因此它返回None
。
通過添加退貨,您應該能夠解決問題,例如
def woodtype(wood):
MAH=float(75.00)
OAK=float(100)
coffetab=float(0)
if wood=="mahogany":
coffetab=MAH
elif wood=="oak":
coffetab=OAK
return coffeetab
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.