Created
July 30, 2024 13:49
-
-
Save JessicaWachtel/e41f0a44267a90244b6d2f1816ef4549 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def divide_numbers(a, b): | |
try: | |
result = a / b | |
return result | |
except ZeroDivisionError: | |
return "Error: Cannot divide by zero." | |
except TypeError: | |
return "Error: Both inputs must be numbers." | |
except Exception as e: | |
return f"An unexpected error occurred: {e}" | |
print(divide_numbers(10, 2)) | |
print(divide_numbers(10, 0)) | |
print(divide_numbers(10, 'a')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment