One plan, three forms
A good designer can move an algorithm between a flowchart, pseudocode and Python without changing what it does. A diamond in a flowchart becomes IF in pseudocode and if in Python. A diamond on a no arrow becomes ELSEIF and then elif. The last no arrow becomes ELSE and then else. The indentation in Python replaces ENDIF. The three versions must give the same answer for every input, so a dry run with the same test values is a good check. When lines of a program are mixed up, put the first line first, find the if, then the elif parts in order and the else last. Then check the indentation.
1INPUT level 2IF level < 20 THEN 3 OUTPUT "Refill now" 4ELSEIF level < 60 THEN 5 OUTPUT "Half full" 6ELSE 7 OUTPUT "Plenty" 8ENDIF
1level = int(input("Level percent? ")) 2if level < 20: 3 print("Refill now") 4elif level < 60: 5 print("Half full") 6else: 7 print("Plenty")
Half full
| level typed | Flowchart path | Pseudocode output | Python output |
|---|---|---|---|
| 10 | yes at first diamond | Refill now | Refill now |
| 20 | no, then yes | Half full | Half full |
| 59 | no, then yes | Half full | Half full |
| 60 | no, then no | Plenty | Plenty |
Three forms game (no computer). Work in a team of three. Choose a situation with three outcomes, such as the amount of light in a room or the number of players for a team game. Person A draws the flowchart, Person B writes the pseudocode and Person C writes the Python. Do not look at each other’s work until all three are finished. Then each person dry-runs another person’s version with the same three test values and compares answers. Fix any version that disagrees. Cut the Python program into strips, one line per strip, shuffle them, and let another team put them back in order. If you have a computer or tablet, type your Python program and run it.
| Letter | Line |
|---|---|
| A | print("Nearly full") |
| B | passengers = int(input("Passengers? ")) |
| C | else: |
| D | if passengers > 40: |
| E | print("Seats free") |
| F | elif passengers > 30: |
| G | print("Bus is full") |
1mood = input("Mood? ") 2if mood = "happy": 3 print("Smile") 4else if mood == "tired": 5 print("Rest") 6else 7 print("Carry on")