Part 2 – Error handling, using loops, and if/else/elif statements
In this Insight, we tackle the problem we left off in the last Insight – an error that occurs upon entering something other than a valid integer. After solving that, we add support for more than two numbers and a choice between adding and multiplying them.
In tackling the above problems, you’ll learn how to troubleshoot – and build your code – by writing down what you’re trying to accomplish. Using plain language comments to describe your intentions adds great clarity to the code you’ll be writing. And if anyone needs to read your code in the future, it makes it easy for them to understand your intentions.
Key takeaways from this Insight
By the end of this Insight, you should understand:
- Handling errors with try & except
- Using while loops
- Using for loops
- Using break for getting out of loops
- Defining a list of indeterminate length, and ‘appending’ to the list
- Using try, except
- Using range to determine the size of the list
- Use conditionals if, else, and elif
- Give the user options after inputting data
- Debug errors in our code and use Print to check our code as we work
- A significant limitation of Code Editor software error-checking
Questions or Comments?
How did I do with this Insight? Are you able to follow along Let me know! I’m recording this tutorial series one at a time, after I see your feedback. If you need anything clarified or have an idea for code you’d like us to build together, use the comments! If you would rather I speed things up and record a few Insights at a time, I’m also open to the idea of getting through this series in a shorter time.