Page 294 - AI Ver 1.0 Class 9
P. 294

Task



             Solve the following expressions using the operator precedence:

             •  10 + 20 / 5 – 3 * 2
             •  5 * (10 + 5) + 10 – 5




                 Comments in Python


        Comments are used to increase the readability of the code. We use them to give proper understanding of the
        code in simple English statements. They are completely ignored by the Python interpreter. It is always a good
        practice to add comments in your code so that if anybody in future wish to understand or modify your code,
        then through comments it will be easy to interpret the instructions. There are two different ways of writing
        comments in Python. Let us learn about them in detail.


        Single Line Comment
        Single line comment starts with hash symbol # followed by the text to be written as a comment that lasts till the
        end of the line.

        For example,

         # assigning a value to a variable
              num1 = 10

              num2 = 20

        # calculating the average
              (num1 + num2) / 2

        Multiple Line Comments

        When we add up comments which occupy two or more lines then we begin the comment with either 3 times
        single quotes ''' or double quotes """, followed by text on multiple lines and end with single quotes ''' or double
        quotes """ to mark the end of the comment. For example,


          """This program calculates
              the average of

              two numbers stored in
              two different variables"""

              a = 10

              b = 20
              c = (a + b) / 2






                  292   Touchpad Artificial Intelligence-IX
   289   290   291   292   293   294   295   296   297   298   299