您好,登錄后才能下訂單哦!
def sgn(x):
try:
if x > 0:
return 1
elif x < 0:
return -1
else:
return 0
except TypeError:
print("Error: Input must be a numeric value")
except Exception as e:
print("An error occurred:", e)
# Test the sgn function with some values
print(sgn(5)) # Output: 1
print(sgn(-3)) # Output: -1
print(sgn(0)) # Output: 0
print(sgn('a')) # Output: Error: Input must be a numeric value
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。