Python TypeError:不支持+的操作数类型:“int”和“NoneType”

2024-09-30 14:31:38 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我第一次上编程课,我很难解决这个问题。我似乎无法实现我一直在获取“TypeError:unsupported operandom type for+:'int'and'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)

Tags: theyouinputtablesistypefloatint
1条回答
网友
1楼 · 发布于 2024-09-30 14:31:38

您的函数woodtype似乎缩进不良,并且没有返回语句,因此它返回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

相关问题 更多 >