0% found this document useful (0 votes)
11 views4 pages

Computer 1

Uploaded by

Ansgar Noble
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Computer 1

Uploaded by

Ansgar Noble
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

COMPUTER

SCIENCE

MOHAMED FARRIS

XI-B
Errors in a Program
Errors in programming refer to issues or defects that arise
within the program, resulting in abnormal behavior. Even
experienced developers can make these mistakes, which are
also referred to as bugs or faults. The process of eliminating
these errors is called debugging.

Error refers to issues that occur in a program that results in


unwanted behavior of the program. Some common Types of Errors
in Programming are listed below.
• Syntax Error
• Run-Time Error
• Logical Error

Syntax Error;
Syntax errors are the most basic type of error. They arise when the
Python parser is unable to understand a line of code. Syntax errors are
almost always fatal, i.e. there is almost never a way to successfully
execute a piece of code containing syntax errors.

In IDLE, it will highlight where the syntax error is. Most syntax errors
are typos, incorrect indentation, or incorrect arguments. If you get this
error, try looking at your code for any of these.

Example:

print "Hello World!"

Common Python syntax errors include:

• leaving out a keyword


• putting a keyword in the wrong place
• leaving out a symbol, such as a colon, comma or brackets
• misspelling a keyword
• incorrect indentation
• empty block

Here are some examples of syntax errors in Python:

myfunction(x, y):
return x + y

else:
print("Hello!")

if mark >= 50
print("You passed!")

if arriving:
print("Hi!")
esle:
print("Bye!")

if flag:
print("Flag is set!")

Run-time Error
Run time errors arise when the python knows what to do with a
piece of code but is unable to perform the action. Since Python is
an interpreted language, these errors will not occur until the
flow of control in your program reaches the line with the
problem. Common example of runtime errors are using an
undefined variable or mistyped the variable name.
Example of Run-Time Error

• division by zero
• performing an operation on incompatible types
• using an identifier which has not been defined
• accessing a list element, dictionary value or object attribute which doesn’t
exist
• trying to access a file which doesn’t exist
Logical Error;
These are the most difficult type of error to find, because they
will give unpredictable results and may crash your program. A
lot of different things can happen if you have a logic error.

Here are some examples of mistakes which lead to logical errors:

• using the wrong variable name


• indenting a block to the wrong level
• using integer division instead of floating point division
• getting operator precedence wrong
• making a mistake in a boolean expression
• off-by-one, and other numerical errors

Example: For example, perhaps you want a program to calculate


the average of two numbers and get the result like this :

x = 3
y = 4
average = x + y / 2
print(average)
Output

5.0

You might also like