top of page
Search

Paradigm: Try, Except, Finally

Updated: May 1


Imperative Programming: exception handling



def division_error_handling(num1, num2):
    try:
        result = num1 / num2
        print(f"The result is {result}")
    except ZeroDivisionError:
        print("Error: Cannot divide by zero.")
    except ValueError:
        print("Error: Please enter a valid number.")
    finally:
        print("Operation completed.")

division_error_handling(num1=5, num2=0)








5 views

コメント


bottom of page