Results of races are kept as records with three fields: the race name, the competitor's number and the time taken in seconds (Figure 10). Figure 11 makes two such records. Later, every competitor's time in one race is held in a real-number array named times, and the quickest is its smallest entry.
Write the pseudo-code line creating record race3 for event 200 m, runner 10, time 32.59, following Figure 11.
Our own questions on this topic, marked straight away, so you see what to revise. Free now.
Show model answer for 10.1Hide model answer for 10.1
race3 ← Runner('200 m', 10, 32.59)How the marks are earned
- The line assigns to race3 a call of Runner holding three values in order: the event name in quotes ('200 m'), the number 10 and the time 32.59, inside brackets and separated by commas.
- Case is ignored.
- Missing quotes, commas or brackets earn nothing.
Write the pseudo-code line that outputs the time stored in record race2 (Figure 11).
See how you would score on Data TypesShow model answer for 10.2Hide model answer for 10.2
OUTPUT race2.timeHow the marks are earned
- OUTPUT race2.time, with the field name after a full stop.
- Case is ignored.
- A missing full stop earns nothing.
Write Python to find and print the smallest value in times, any size, with no built-in minimum or sort routine.
See how you would score on Iteration (Loops)Show model answer for 10.3Hide model answer for 10.3
fastest = times[0]
for position in range(1, len(times)):
if times[position] < fastest:
fastest = times[position]
print(fastest)How the marks are earned
- The program works out or uses how many items times holds (design mark). A loop over each item of times, with no length worked out, is also accepted.
- A variable is set to a suitable number to hold the fastest time, or the position of the fastest time.
- A loop visits every item, however many the array holds. The loop may start at the second item when the variable starts at the first item.
- At least twice, a value from the array is compared with the best time so far to see whether it is lower, even if the indexing is wrong.
- The current fastest time, or its position, is stored correctly on each pass, with correct indexing.
- The fastest time is output once, from a variable, in a suitable place.
- A built-in routine that finds the smallest value or sorts the array loses the checking mark and the storing mark.
- The case of the code is ignored; gaps are ignored unless they change the logic.
- If the code has any error, the maximum is 5 marks.
- The design mark is for choosing a suitable technique and is credited whether or not the syntax is correct and whether or not the program works.
Why it scores
len(times) makes the loop fit an array of any size. fastest starts as the first time, and each later time is compared with it. A smaller time replaces fastest, so after the loop it holds the smallest value, which is printed once. No min() or sort is used.
Revise Iteration (Loops)