Making a design • In this class we use the words “design”, “pseudocode” and “algorithm” interchangeably • These are steps to solve a problem, they involve writing down a design for the solution • A design is similar to a rough draft or an outline for an essay • It’s meant to be a thinking tool, it will not be neat. You will make corrections, additions, deletions, reorderings
Building a dog house • decide on location for house • decide on size of house • get plans for house • get materials for house • cut wood for bottom of house • put bottom platform together • cut wood for 4 walls of house • assemble walls • attach walls to bottom • cut door • make roof • attach roof to walls • paint outside
Notes about the design • The steps are numbered in the order they will be done – we will ask you to do that for the first few designs you do, just to get the feel for how much is one “step” • Several of the steps should be subdivided, like step 4 would include the store you would buy the materials from, a list of the materials needed, possibly prices • Step 7 could be written as a repetition Repeat 4 times cut wood for a wall • The order of several steps can be rearranged, like step 10 could be after step 11 • Several steps could have more detail – the size of the dog would determine the size of the house, the location would depend on the size of the yard, the climate, the direction the house faces, • Some people would make notes about insulation or a fan or A/C • Assumptions about budget would be noted at the top
Building a dog house (with some refinements) • Decide on location for house • Decide on size of house • Get plans for house • Get materials for house • Get lumber • Get insulation • Get paint • Get nails • Cut wood for bottom of house • Put bottom platform together • Repeat 4 times • Cut wood for a wall of house • Assemble walls • Attach walls to bottom • Cut door in front side of house • Make roof • Attach roof to walls • Paint outside
How to do a design in this class • Use an editor that creates a text file. The editors from IDLE or WingIDE work fine. Notepad is also ok. • State the purpose of the design at the top • Put your name, section and email at the top • Number the steps (hint: wait until you have the design finished before you number the steps, aggravating to have to renumber) • Enter the steps in the editor as Python comments, using # or ‘’’ • Write the steps in English, NOT Python!
Program design (in a file called design1.py) #Purpose: ask for a user’s name and say hello to them # Author: John Smith, section 1, firstname.lastname@example.org #The main function #1. input the user’s name from the keyboard #2. output the name with the word hello before the name • Save this as something like design1.py • You ask why do I save it as a Python file? This file will be the basis of the actual implementation (Python) file • Just load it into your editor and write Python code to do each step of the design – voila! You have your documentation done!
Implementation with design between code lines (in a file called greeting.py) #Purpose: ask for a user’s name and say hello to them # Author: John Smith, section 1, email@example.com #The main function def main (): #1. input the user’s name from the keyboard name = input(“Your name? “) #2. output the name with the word hello before the name print(“Hello”, name) main()