Lesson 6/6High school~60 min
Exceptions (try – except)
A program that does not crash on bad input: asking again for a number, division by zero and several `except` branches.
You can solve exercises without signing in; sign in and your progress is kept.
After this lesson you'll be able to:
- Catch a
ValueErrorwhen turning text into a number - Tell several kinds of errors apart with
exceptbranches - Understand the order of
try,except,elseandfinally
What you practise here
- try – except
- while loops
- Kinds of exceptions: ValueError, ZeroDivisionError, …
- Validating input
- Reading numbers from input
- Integer division and remainder: // and %
- Several branches: elif
- break and continue
- Return values: return
- Splitting and joining: split() and join()
+ 3
Short tasks that check you understand: multiple choice, predicting the output, finding the bug, completing code.
Start the exercisesReal programming tasks: write a program, run it and submit it to be checked, hidden tests included.
Start the challenges