Articles
The problem...
Your program asks for a number. The user types a word. Python crashes.
age = int(input("Enter your age: ")) # user types "abc"
# ValueError: invalid literal f…
The problem...
You know try / except. You catch the error. You handle it. Done.
But sometimes you need more. Code that runs only when everything worked. Code that runs no matter…
The problem...
Python raises errors when something goes wrong — wrong type, wrong value, division by zero.
But sometimes you need to raise an error yourself. The input is …
The problem...
You've built the BMI Calculator three times. Each version was better than the last.
But none of them handled bad input. Type a word — crash. Enter a negativ…
The problem...
Your function doesn't return what you expect. Or it crashes on valid input. Or it changes a variable that shouldn't change.
These are the mistakes almost every be…
The idea!
You've covered def, parameters, default parameters, return, scope, multiple return values, try/except, and raise.
This is your reference. Everything in one place.
Com…