Design a Problem Solution. Making a design In this class we use the words “design”,...

9
Design a Problem Solution

Transcript of Design a Problem Solution. Making a design In this class we use the words “design”,...

Page 1: Design a Problem Solution. Making a design In this class we use the words “design”, “pseudocode” and “algorithm” interchangeably These are steps to solve.

Design a Problem Solution

Page 2: Design a Problem Solution. Making a design In this class we use the words “design”, “pseudocode” and “algorithm” interchangeably These are steps to solve.

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

Page 3: Design a Problem Solution. Making a design In this class we use the words “design”, “pseudocode” and “algorithm” interchangeably These are steps to solve.

Problem – build a dog house

Page 4: Design a Problem Solution. Making a design In this class we use the words “design”, “pseudocode” and “algorithm” interchangeably These are steps to solve.

Building a dog house

1. decide on location for house2. decide on size of house3. get plans for house4. get materials for house5. cut wood for bottom of house6. put bottom platform together 7. cut wood for 4 walls of house8. assemble walls9. attach walls to bottom10. cut door11. make roof12. attach roof to walls13. paint outside

Page 5: Design a Problem Solution. Making a design In this class we use the words “design”, “pseudocode” and “algorithm” interchangeably These are steps to solve.

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 repetitionRepeat 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

Page 6: Design a Problem Solution. Making a design In this class we use the words “design”, “pseudocode” and “algorithm” interchangeably These are steps to solve.

Building a dog house (with some refinements)1. Decide on location for house2. Decide on size of house3. Get plans for house4. Get materials for house

1. Get lumber2. Get insulation3. Get paint4. Get nails

5. Cut wood for bottom of house6. Put bottom platform together 7. Repeat 4 times

1. Cut wood for a wall of house

8. Assemble walls9. Attach walls to bottom10. Cut door in front side of house11. Make roof12. Attach roof to walls13. Paint outside

Page 7: Design a Problem Solution. Making a design In this class we use the words “design”, “pseudocode” and “algorithm” interchangeably These are steps to solve.

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!

Page 8: Design a Problem Solution. Making a design In this class we use the words “design”, “pseudocode” and “algorithm” interchangeably These are steps to solve.

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, [email protected]#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!

Page 9: Design a Problem Solution. Making a design In this class we use the words “design”, “pseudocode” and “algorithm” interchangeably These are steps to solve.

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 protected]#The main functiondef 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()