Читать книгу Introduction to Python Programming for Business and Social Science Applications - Frederick Kaefer - Страница 56

Stop, Code, and Understand! SCU 2.5 Logic Errors

Оглавление

Download the file “SCU 2_5.py” from the companion website and save it either on your computer or on a removable storage device. Open the file in the Python IDLE editor and execute the program to see that it runs but does not have the correct result. Add parentheses around the two values being added in the assignment statement in the line indicated to resolve the issue. Execute the modified program to verify that the revised code runs and produces the correct result.

Description

Lessons learned: In this section, we learned there are three types of errors in Python: syntax errors, exceptions, and logic errors. Syntax errors are the easiest types of errors to resolve and result when we do not follow the rules for correctly specifying Python code. Exceptions are the types of errors that occur when we attempt to do something in Python that is not possible or not allowed. Logic errors occur when code executes without terminating with an error message but has incorrect results. We will encounter each of these error types often as we develop code but will learn and become better at diagnosing them and improving our code.

Introduction to Python Programming for Business and Social Science Applications

Подняться наверх