Which path comes first?
Answers are for parents and teachers.
1
Follow the algorithm for the inputs 3, 4 and 12. What is shown each time?
Pseudocode
1INPUT n 2IF n > 10 THEN 3 OUTPUT "Stay out" 4ELSEIF n > 4 THEN 5 OUTPUT "Paddle only" 6ELSE 7 OUTPUT "Safe to splash" 8ENDIF
3: Safe to splash. 4: Safe to splash. 12: Stay out. The first true condition decides.
2
Write pseudocode: the user types the number of tickets sold. Below 50 shows Slow, below 200 shows Steady, below 500 shows Busy and anything else shows Sold out soon.
INPUT sold / IF sold < 50 THEN OUTPUT "Slow" / ELSEIF sold < 200 THEN OUTPUT "Steady" / ELSEIF sold < 500 THEN OUTPUT "Busy" / ELSE OUTPUT "Sold out soon" / ENDIF.
3
A programmer wrote IF mark >= 40 ... ELSEIF mark >= 70 ... ELSE .... Explain what is wrong with the order and how to fix it.
Every mark of 70 or more is already at least 40, so the second condition can never be reached. Test the larger boundary first: IF mark >= 70 ... ELSEIF mark >= 40 ... ELSE ....
4
List the boundary values you would test for the fare program in lesson 2 (ranges below 5, up to 17, up to 64, and over 64) and say why.
4 and 5, 17 and 18, 64 and 65. These values are on either side of each boundary, so a mistake with < or <= would show up.
5
In your own words, say what a case statement does and why Python programmers use if and elif instead.
A case statement compares one variable with several fixed values and runs the matching part. Python has no case statement in this course, so programmers write a chain of if and elif statements to do the same job.