Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 104 - 2615_KEC
P. 104

    ERRORS IN PYTHON PROGRAMS

                      Errors are faults in a program. Errors prevent a program from executing accurately. There can be
                      the following types of errors in a Python program:

                      SYNTAX ERRORS
                      A syntax error will occur when these rules and regulations are violated. For Example:

                          IDLE Shell 3.10.5

                       File  Edit  Format    Run   Options   Window    Help      Invalid Syntax
                                                                                 Parentheses missing
                        >>> print"Hello"
                        SyntaxError: Missing parentheses in call to 'print'. Did you mean >>> print("Hello")?
                        >>> print("Hello")
                        Hello

                      LOGICAL ERRORS
                      As the name suggests, these errors are related to the logic of the program. These errors are also

                      known as semantic errors. They cause the program to behave incorrectly. They are the most
                      difficult errors to fix but they do not usually crash the program.
                      For example:

                          IDLE Shell 3.10.5
                       File  Edit  Format    Run   Options   Window    Help

                        >>> #Example of Logical Errors in a Program
                        >>> num1=float(input('Enter a number:'))
                        Enter a number:7
                        >>> num2=float(input('Enter another number:'))
                        Enter another number:8
                        >>> average=num1+num2/2                Invalid Logic
                        >>> print(average)                     The average of 8 and 7 should be
                        11.0                                   7.5 Put num1 + num2 in braces as
                        >>>                                    (num1+num2) for correct result.

                      RUN-TIME ERRORS

                      Run-time errors in Python occur while the program is executing, causing it to crash or behave
                      unexpectedly. These errors arise due to issues such as invalid operations, unavailable resources
                      or invalid inputs.

                      102   Premium Edition-VII

| 99 100 101 102 103 104 105 106 107 108 109 |