定義函數(shù)的問題
# Enter a code
x=100
def my_abs(x):
? ? if not isinstance(x, int) or not isinstance(x, float):
? ? ? ? print('param type error.')
? ? ? ? return None
? ? if x >= 0:
? ? ? ? return x
? ? else:
? ? ? ? return -x
result=my_abs(x)
print(result)
#這個(gè)程序,求絕對(duì)值。輸入x=100,怎么結(jié)果還是
param type error.
None
呢?我是把老師的課例代碼復(fù)制過去的,然后在后面增加了print()語句。
應(yīng)該的結(jié)果是100啊。
請(qǐng)老師指點(diǎn)
2021-02-22
確實(shí),絕對(duì)是and,同道中人
2021-01-13
聰明呀,確實(shí)是這樣!
2020-09-10
我找到問題了,語句中的or 應(yīng)該是and
既不是整數(shù)型,也不是浮點(diǎn)數(shù)
我發(fā)現(xiàn)講課老師的一個(gè)bug了