CSC 171 - Introduction to Computer Programming

Lab Assignment #3 - Pseudocode and Stepwise Refinement

Due Wednesday, September 7, 2022

The term "Pseudocode" means something that looks like computer program code but really isn't. We saw this in our second programming assignment when we wrote out the first few steps:

1. Add up these values
2. Divide the sum by the number of values
3. Print the result

This is an example of pseudocode: it breaks down the logic of our program into a certain amount of detail. In the example from class, we only need a few more details before we start writing our program in Python. Let’s look at another example: we will have the user enter his/her height in feet and inches; we will then display it in centimeters.

Our initial algorithm is:
1. Ask for the user's height
2. Convert it into centimeters
3. Display the user's height in centimeters.

Obviously, this does not enough detail yet. We need to indicate that we are getting the height in feet AND inches:
1.1 Tell the user you want his/her height in feet and inches
1.2 Ask how many feet and read it
1.3 Ask how may inches and read it
2.1 Convert feet and inches to inches
2.2 Convert inches to centimeters
3. Display the user's height in centimeters

Now we need to know how to do the conversion: 1.1 Tell the user you want his/her height in feet and inches
1.2 Ask how many feet and read it
1.3 Ask how may inches and read it
2.1 Total inches = 12 * feet + inches
2.2 Height in centimeters = 2.54 * total inches
3. Display the user's height in centimeters

This process is called stepwise refinement

What you are going to do for the lab is similar to what you see here: Your program is going to ask the user for his/her age. Your program will calculate and then print how old the user will be in five years. BUT DON'T RUSH AND WRITE THE PROGRAM!!

Start with the basic three step algorithm you saw above. Expand it before you write the code. And draw a flowchart for it.

You are submitting your refined algorithm (and SHOW YOUR WORK!!), the flowchart and as a separate file your Python program. You can submit the expanded pseudocode and as one file or two separate files. But the Python program is a file with the extension .py

[Back to the Lab Assignment List]