2016-06-21 57 views
-8

這是我第一次編程課,我很難解決這個問題。我似乎無法得到這個工作,我不斷收到「類型錯誤:不支持的操作數類型(S)爲+:‘詮釋’和「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) 
+2

你的函數'woodtype(wood)'不返回任何東西,所以這個變量被賦值爲'None'。 –

+0

https://docs.python.org/3/tutorial/controlflow.html#defining-functions –

+4

StackOverflow是一個問答網站,而不是幫助論壇。這個區別至關重要:我們關心質量問題,就像我們的答案一樣,因爲問題也是內容。請嘗試遵循http://stackoverflow.com/help/mcve中的規則;將代碼部分的內容最小化,以便集中關注單個具體錯誤,並刪除不需要的所有內容;並在你的問題標題中反映出這個錯誤的性質(這也是其他具有相同問題的人如何找到這個問題及其答案的原因)。 –

回答

0

你的功能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 
+1

仍然沒有任何。 'wood'將是有效的,而不是'woodtype' – Li357

+0

DEF木:() MAH =浮子(75.00) OAK =浮子(100) coffetab =浮子(0) 如果木== 「紅木」: coffetab = MAH elif wood ==「oak」: coffetab = OAK return coffeetab –

+0

^所以我會這樣做,而不是^? –

相關問題