...

/

Try Things Out Safely!

Try Things Out Safely!

Learn how to catch and handle user input errors safely.

Our code can now make decisions, but what happens when something goes wrong?
In this lesson, we’ll learn how to use try and except to handle errors and keep our programs from crashing.


Let’s break something (on purpose)

Try running this:

number = int(input("Enter a number: "))
print("Half of your number is", number / 2)
Asking for a number and dividing it by 2

Now run it again, but instead of entering a number, type something like hello. ...