Page 49 - Code & Click - 7
P. 49

2. Press the F5 key to execute the code. Sample output of the program is given below.


















            INDENTATION OF STATEMENTS IN PYTHON
            Indentation  is  the  process  of  starting  text  from  a  position  away  from  the  page  margin.  Most
            programming languages implement indentation of statements for better readability and clarity of code.
            Some programming languages make indentation of statements optional and allow for statements to
            be written aligned with the margin. But, Python makes indentation of statements compulsory.

            Each block of statements in Python starts with a colon ( : ), and the set of statements under the block are
            indented. The usual indentation under a block is four spaces, or a multiple of four spaces. Thus, all statements
            under a particular if statement will be indented by the same number of spaces. This helps in structuring the
            program in an organised manner and visualising the different blocks of statements easily.

             Knowledge Discovery                                                                 Subject Enrichment

             Simple statements, executed at the Python prompt in the Interpreter window, do not require indentation,
             but compound statements must be indented. Similar levels of statements in a block must be indented by
             the same number of spaces.

                                                                                                 Experiential Learning
              Lab Activity 5

             Program to accept a number from the user and display whether it is divisible by 6 or not.
             1. Type the code as shown in the image in the Python Editor.












             2. Press the F5 key to execute the code. Sample output of the program is given below.
















                                                                                                                 47
   44   45   46   47   48   49   50   51   52   53   54