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 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, the programmer has violated the grammar (rules) of Python programming language. The python points these type of errors, whenever it is noticed by the python interpreter. Sometime 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.

READ  Classes and Methods in Python

Logic errors. A logic error occures when the program is correctly written by following all the syntactical rules but the mistake is made in arranging the statements in a 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 in a variable say n. The input read using inpput() function is string type. Hence first convert it to intger form using int() function. Then find the value of 22*n + 1 and display the rusult to user using 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

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.

READ  Solution to Python Application Programming Question Paper July 2018

Leave a Comment

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