2021-02-21 19:22:50 +04:00

18 lines
392 B
Python

#exception3.py
import math
def sqrt(num):
if not isinstance(num, (int, float)) :
raise TypeError("only numbers are allowed")
if num < 0:
raise Exception ("Negative number not supported")
return math.sqrt(num)
if __name__ == "__main__":
try:
print(sqrt(9))
print(sqrt('a'))
print (sqrt(-9))
except Exception as e:
print(e)