Python(Page-4)

 12345678910


Page-4

Debugging

While writing the program, some errors or bugs may be there. The process of identifying and removing errors or bugs is known as Debugging. 
A program may have the following types of errors-
1. Syntax Errors
2. Logical Errors
3. Runtime Errors

Syntax Errors

If the python program is not written as per the rules or syntax acceptable by the python interpreter, it will show an error. Such errors are called syntax errors. 
Example-

print("hello"

This statement will show an error as one right parenthesis")" is missing from the end of the statement. 




Logical Errors

When a program runs without showing any error but does not give the result as desired, it may have logical errors. 

Example-

# program for addition of two numbers

num1=input("enter a num")
num2=input("enter another num")
print(num1+num2)

Here, we have not explicitly converted the string entered by the user, so we will get the concatenation of two values instead of the addition of the numbers. 


Runtime Errors

A run time error may result in abnormal termination of the program. It is called run time error. 

Example-
 
num1=int(input("enter a num\n"))
num2= int(input("enter another num\n"))
print(num1/num2)

In this program, if user enters 0 in num2, the program will terminate abnormally as "divide by zero" error will occur. 



 12345678910

No comments:

Post a Comment