nick34992
5/8/2017 - 1:01 AM

Python: Try, Except, ZeroDivisionError, TypeError

Python: Try, Except, ZeroDivisionError, TypeError

def division_try(anumber):
    try:
        return 100 / anumber
    except ZeroDivisionError:
        return "Sorry, Python does NOT divide by zero."

print(division_try(0))        # exception: ZeroDivisionError
print(division_try(50.0))     # 2.0
print(division_try("hello"))  # exception: TypeError