Page 113 - Computer - 6
P. 113

Lab Activity 1                                                                         Experiential Learning

           Let us create a program to accept the name, class, and age of a student in three variables – Name,
           Class, and Age – and to display them.
            1.  Open a new file.
            2.  Type the code as shown in the image on next page.
            3.  Execute the script.
           The given images display the code and the output of the program.

















          COMMENTS IN PROGRAMS
          Comments are statements that are included in a program to make the code understandable. These are
          non-executable statements and are ignored by the Python interpreter or compiler. 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.
             •  Multi-line comments: Multi-line comments that cover more than one line are enclosed within
                triple quotes (“““ ”””).
                For example,
                # This is a single-line comment.            “““ This is a comment
                                                            that covers multiple lines”””

                 Database                                                                          Subject Enrichment


               Python was developed by Guido van Rossum at Centrum Wiskunde & Informatica (CWI), which is the
               National Research Institute of Mathematics and Computer Science, in Netherlands. Python was first released
               in 1991, and the name ‘Python’ was taken from the popular BBC sitcom ‘Monty Python’s Flying Circus’.


          Post-Processing          
                                 
                                 
              Python is a high-level language used for writing computer programs.
              Script mode and interactive mode (shell mode) are the two modes used for writing Python code.
              Only one command can be executed at a time in interactive mode.
              Script mode is used for writing the computer program.
              Python files are saved with .py extension.

              Print( ) command is used to display output on the screen.
              The Python interpreter can be downloaded from www.python.org.


                                                                                                             111
   108   109   110   111   112   113   114   115   116   117   118