This is my very first programming class and I'm having a hard time with this problem. I can't seem to get this to work I keep getting "TypeError: unsupported operand type(s) 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)
Your function woodtype
appears to be poorly indented, and has no return statement, so it returns None
.
by adding a return you should be able to solve the issues, eg
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.