DEBUGGING
A programmer can make mistakes while coding a program. These mistakes are called bugs or errors in programming language. The program contains bugs may not execute or generate wrong output. The process of identifying and removing such bugs, errors or mistakes is known as debugging. The Errors occurring in programs can be categorised as – Syntax errors, Logical errors and Runtime errors.
Syntax Errors:- Like other programming languages, Python has its own rules that determine its syntax. The interpreter interprets the statements only if it is syntactically (as per the rules of Python) correct. If any syntax error is present, the interpreter shows error message(s) and stops the execution there. For example, parentheses must be in pairs, so the expression (10 + 12) is syntactically correct, whereas (7 + 11 is not due to absence of right parenthesis. Such errors need to be removed before the execution of the program
Logical Errors:- A logical error is a bug in the program that causes it to behave incorrectly. A logical error produces an undesired output but without abrupt termination of the execution of the program. Since the program interprets successfully even when logical errors are present in it, it is sometimes difficult to identify these errors. The only evidence to the existence of logical errors is the wrong output. While working backwards from the output of the program, one can identify what went wrong. For example, if we wish to find the average of two numbers 10 and 12 and we write the code as 10 + 12/2, it would run successfully and produce the result 16. Surely, 16 is not the average of 10 and 12. The correct code to find the average should have been (10 + 12)/2 to give the correct output as 11. Logical errors are also called semantic errors as they occur when the meaning of the program (its semantics) is not correct.
Runtime Error:- A runtime error causes abnormal termination of program while it is executing. Runtime error is when the statement is correct syntactically, but the interpreter cannot execute it. Runtime errors do not appear until after the program starts running or executing. For example, we have a statement having division operation in the program. By mistake, if the denominator entered is zero then it will give a runtime error.