Page 49 - Computer - 7
P. 49

4.  Reserved terms or keywords in Python cannot be used as a variable name.
            5.  Variable names in Python are case-sensitive.

          Input and Output Operations in Python
          The input( ) and print( ) functions help with input and output operations in Python. Input operations
          involve accepting data values from the user and storing them in a variable. Output operations involve
          displaying messages or values of variables and expressions on the screen.

          print( ) Function
          The print( ) function is used to display the value of a variable, an expression, or text messages on the
          screen. The syntax of the print( ) function is:

                 print(text message/variable name/expression)
          To display multiple values with the print( ) function, the values are separated by commas ( , ).
                 print(value1, value2, value3)


                 Knowledge Discovery                                                               Subject Enrichment

               The commas ( , ), used in print( ) function, add a space between the values and display the output in an
               organised manner.


          input( ) Function
          The input( ) function is used to accept data from the user and store it in a variable. The syntax for the
          input( ) command is:
                 <variable name> = input(“Message to display”)
          Comments in Programs
          Comments are non-executable statements in a program that are ignored by the Python interpreter.
          Comments are usually added to a program as documentation notes or to make others understand what
          a part of code does.
          Python allows two types of comments in programs. These are:
             •  Single-line comments: Single-line comments are preceded by the hash (#) symbol.
             •  Multiple-line comments: Multi-line comments that cover more than one line are enclosed within
                triple quotes (“““ ”””).

            Lab Activity 1                                                                         Experiential Learning

           Program in Python to accept data from the user and display it.
           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.



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