What are the three types of errors encountered in python programs

 

What are the three types of errors encountered in python programs?

Mention three types of errors encountered in python programs. Explain the basic building block of python with an example python program to display the format-number (Fn = 22n + 1) for an ‘n’ value prompted by the user.

Solution:

There are three types of errors that occur in the Python programming language, they are syntax errors, Logic errors, and semantic errors.

Syntax errors. Syntax errors are common and first errors in any programming language. These errors can be fixed very easily. The meaning of syntax error is that the programmer has violated the Python programming language’s grammar (rules). The python points these types of errors, whenever it is noticed by the python interpreter. Sometimes the error to be fixed maybe earlier to the noticed line or character. The programmer has to take care of these and do the correction by proper investigation.

Logic errors. A logic error occurs when the program is correctly written by following all the syntactical rules but the mistake is made in arranging the statements in proper order. A good and sensible example for a logical error might be, “take a drink from your water bottle, put it in your backpack, walk to the library, and then put the top back on the bottle.”

Semantic errors. A semantic error occurs when the program is syntactically perfect and all the statements are in the right order, but still, there is a mistake in the program, and you are not getting a correct or expected output.

Python program to display the format-number (Fn = 22n + 1) for an ‘n’ value prompted by the user.

Steps: First read a number and store it in a variable say n. The input read using the input() function is string type. Hence first convert it to integer form using the int() function. Then find the value of 22*n + 1 and display the result to the user using the print() function.

#Read a number and store in num

n = input("Enter a number:")
n = int(n)
fn = 22 * n + 1
print ("The value of 22n + 1 is", fn)

Output:

Enter a number: 10

The value of 22n + 1 is 221

Summary

This tutorial discusses What are the three types of errors encountered in python programs. Subscribe to our YouTube channel for more videos and like the Facebook page for regular updates.

Leave a Comment

Your email address will not be published. Required fields are marked *