Thursday, May 31, 2018

Command-Line Mode(python)

                                                       Command-Line Mode 

 In command-line  mode  , the Python program is still run at the command line but you add the name of a file (that contains your program) to the command: 

                           " python myprogram.py "

   The interpreter reads the contents of the file ( myprogram.py  in this case), scans and validates the code, compiles the program, and then executes the program. If the interpreter encounters a fault in the syntax of your program, it will report a compilation error. If the program fails during execution, you will see a runtime error. If the program executes successfully, you will see the output(s) of the program.  You don’t need to worry about how the interpreter does what it does, but you do need to be familiar with the types of error messages it produces.  We use command-line mode to execute our programs in files.

  Coding, Testing and Debugging Python Programs

  The normal sequence of steps when creating a new program is as follows:

   1.    Create a new  .py  file that will contain the Python program (sometimes called source code). 

  2.    Edit your  .py  file to create new code (or amend existing code) and save the file.
   
3.    Run your program at the command prompt to test it, and interpret the outcome.
 
  4.    If the program does not work as required, or you need to add more features, figure out what changes are required and go to Step 2.

It’s usually a good idea to document your code with comments.

This is part of the editing process, Step 2. If you need to make changes to a working program, again, you start at Step 2.  Writing new programs is often called   coding   . When your programs don’t work properly, getting programs to do exactly what you want them to do is often called   debugging .  .      

No comments:

Post a Comment