Page 63 - Computer - 7
P. 63

1. Type the code as shown in the image in the Python Editor.
























           2. Press the F5 key to execute the code. Sample outputs of the program are 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.



                                                                                                              61
   58   59   60   61   62   63   64   65   66   67   68