所以我運行python 2.7,並且我一直試圖讓這個代碼顯示與輸入(cha)相對應的數字(chamod),但是它一直返回0.我怎樣才能得到它得到相應的輸出?它應該打印出2.Python函數總是返回0
def charismamod(cha):
chamod = 0
if cha == 1:
chamod = -5
elif cha == 2 | cha == 3:
chamod = -4
elif cha == 4 | cha == 5:
chamod = -3
elif cha == 6 | cha == 7:
chamod = -2
elif cha == 8 | cha == 9:
chamod = -1
elif cha == 10 | cha == 11:
chamod = 0
elif cha == 12 | cha == 13:
chamod = 1
elif cha == 14 | cha == 15:
chamod = 2
elif cha == 16 | cha == 17:
chamod = 3
elif cha == 18 | cha == 19:
chamod = 4
elif cha == 20:
chamod = 5
return chamod
def barbarian():
cha = 14
bchamod = charismamod(cha)
print bchamod
barbarian()
其實它是'或' – cdonts
@cdonts謝謝! ||顯示爲無效語法。什麼|那麼呢? –
'|'是*按位或*。請參閱[BitwiseOperators](https://wiki.python.org/moin/BitwiseOperators)。 – cdonts