0
def absolutevalue(num):
if num >= 0:
abs_num = num
else:
abs_num = -num
print("The absolute value"+ abs_num)
如果我嘗試運行功能absolutevalue(4)
,它拋出的錯誤如下類型錯誤:必須海峽,不是int --Python錯誤Spyder的應用
Traceback (most recent call last):
File "<ipython-input-16-36bd355eb83d>", line 1, in <module>
absolutevalue(4)
File "<ipython-input-15-42a3de37c325>", line 6, in absolutevalue
print("The absolute value"+ abs_num)
TypeError: must be str, not int