Introduction
The purpose of this project component is to provide a first experience in the actual writing of computer programs. Using a relatively simple introductory scripting language (Python), you will create program code in an editor (Notepad), save it to your disk, and run it from the command line prompt.
You will gain experience in planning, writing, debugging, documenting, and running simple programs. Learning Python serves as a convenient stepping-stone to more complex object-oriented languages, such as Java.
In this project, you will use online resources, including downloadable Python tools and tutorials.
Before writing programs, it is useful to plan the programming steps and actions by writing an algorithm. An algorithm is a set of plain English language commands or steps, each of which is then replaced by the appropriate command line for the programming language used. This technique becomes less useful when using complex object-oriented languages such as Java, but may be helpful in the early stages of learning to design programs. You will write algorithms for your first two programming exercises in this project.
The project will be graded for completeness and correct functioning of programs.
Acquiring the Tools
Download and install Python version 2.2 or higher by following the instructions at the Python download site.
The downloaded file will be called Python-2_2.exe. After downloading, run this file to complete the installation. You can view the installed components from your “Start” list.
Writing Algorithms
In the traditional approach to programming, the program is seen as a series of steps, which may include branches and loops. A branch occurs when a program may go in two or more different directions, depending upon a logical condition or a choice made by the user. A loop is a situation where a particular step, or series of steps, may be repeated until a certain condition or choice occurs.
The following simple example of an algorithm includes both elements, and describes a simple program for performing addition or multiplication.
Step 1—display the program name “Addition and Multiplication”
Step 2—display the options menu “(A)dd, (M)ultiply”
Step 3—request and store input of user choice A or M as “choice”
Step 4—if “choice” does not equal “A” or “M”, go to Step 9
Step 5—request and store the first number to be used as variable X
Step 6—request and store the second number to be used as variable Y
Step 7—if “choice” = “A” go to Step 11
Step 8—if “choice” = “M” go to Step 13
Step 9—display message “Choose A or M”
Step 10—go to Step 3
Step 11—display “Sum is” X+Y
Step 12—go to Step 3
Step 13—display “Product is” X*Y
Step 14—go to Step 3
Writing, Storing, and Running Python Programs
The actions involved in creating and running Python programs are relatively simple:
Input the code using Notepad, and save the file as *.py (e.g., prog1.py). Save your programs in the Python folder on your hard disk.
Open the MS-DOS prompt window.
Change directory from Windows to Python22 (enter “cd”