Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JessicaWachtel/e41f0a44267a90244b6d2f1816ef4549 to your computer and use it in GitHub Desktop.
Save JessicaWachtel/e41f0a44267a90244b6d2f1816ef4549 to your computer and use it in GitHub Desktop.
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