Page 75 - IPP-11
P. 75
In the above example, we have typed Print() statement instead of print(), which is syntactically
wrong and needs to be corrected. So the correct statement shall be:
>>> print(4+5)
9
Most syntactical errors occur at the time of program execution and the interpreter points them
out for you. Fixing the error is made easy because the interpreter generally tells you what to
fix and with considerable accuracy.
CTM: Syntax errors are errors that occur due to incorrect format of a Python statement. They occur
while the statement is being translated to machine language and before being executed.
A few more examples of syntax errors are shown below in Fig. 3.21.
Supplement – Informatics Practices with Python–XI
Fig. 3.21: Other types of Syntax Errors
Let us understand the reason behind the occurrence of each error given in the above example.
Statement 1 generates syntax error because of improper closing bracket (square bracket
instead of parenthesis).
Statement 2 generates syntax error because of missing parenthesis after ‘if’ keyword.
Statement 3 generates syntax error because of missing parenthesis with print() method.
Statement 4 generates syntax error because of use of semicolon instead of comma in a list
declaration.
Statement 5 generates syntax error because of improper indentation.
3.15.2 Runtime Error
A runtime error occurs after Python interpreter interprets the code you write and the computer
begins to execute it. Runtime errors come in different types and some are hard to find.
You know you have a runtime error when the application suddenly stops running and displays
an error (exception) dialog box or when the user complains about erroneous output. It usually
results in abnormal program termination during execution.
3.6