Words before code
Answers are for parents and teachers.
1
Write these two lines in another valid pseudocode style, and then in Python: total ← price * 3 and OUTPUT "Total: ", total.
For example: total = price * 3 and PRINT "Total: " & total. Python: total = price * 3 and print("Total:", total). Any clear, consistent style is valid pseudocode.
2
Follow the algorithm for the inputs 4, 10 and 25. What is output each time?
Pseudocode
1INPUT n 2IF n > 10 THEN 3 n ← 10 4ENDIF 5OUTPUT n * 3
4: 4 > 10 is false, so n stays 4 and the output is 12. 10: 10 > 10 is false, output 30. 25: n becomes 10, output 30.
3
This algorithm should show Freezing for 0 degrees or colder. Edit it to do that. Then add a new task: if the temperature is below −10 it must also show Stay in. Write the edited algorithm.
Pseudocode
1INPUT temp 2IF temp < 0 THEN 3 OUTPUT "Freezing" 4ELSE 5 OUTPUT "Not freezing" 6ENDIF
Change the condition to temp <= 0. Add, after the ENDIF: IF temp < -10 THEN / OUTPUT "Stay in" / ENDIF. For −12 both Freezing and Stay in are shown.
4
This algorithm should work out the average of three marks. The user types 6, 9 and 12. Find the error, say what is output, and correct it.
Pseudocode
1INPUT a 2INPUT b 3INPUT c 4average ← a + b + c / 3 5OUTPUT average
The output is 19, because 12 / 3 is worked out first and added to 6 + 9. The average should be 9. Correct line: average ← (a + b + c) / 3.
5
Why do designers write pseudocode before they write a program in Python?
Pseudocode lets them plan the steps without worrying about the strict syntax of a language. It is quick to write and change, it can be turned into any language, and mistakes in the logic can be found before the real program is written.