定義函數的問題
# 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)
#這個程序,求絕對值。輸入x=100,怎么結果還是
param type error.
None
呢?我是把老師的課例代碼復制過去的,然后在后面增加了print()語句。
應該的結果是100啊。
請老師指點
2021-02-22
確實,絕對是and,同道中人
2021-01-13
聰明呀,確實是這樣!
2020-09-10
我找到問題了,語句中的or 應該是and
既不是整數型,也不是浮點數
我發現講課老師的一個bug了