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)
Visit GitHub: https://github.com/datanota/full-stack
コメント