Computer 1
Computer 1
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.
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:
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.
x = 3
y = 4
average = x + y / 2
print(average)
Output
5.0