AQA GCSE · Question 11.1 · Fundamentals of algorithms
Figure 10 shows part of an algorithm that has been written in pseudo-code. There is an error in the algorithm.
The algorithm should:
- get the start year and end year from the user
- check that the start year is before the end year
- check that the start year is before 2000
- calculate the difference between the two years after a valid start year has been entered.
Figure 10
1 validChoice ← False
2 REPEAT
3 difference ← -1
4 OUTPUT 'Enter a start year '
5 startYear ← USERINPUT
6 OUTPUT 'Enter an end year '
7 endYear ← USERINPUT
8 IF startYear >= endYear THEN
9 OUTPUT 'Start year must be before end year'
10 ELSE
11 IF startYear < 2000 THEN
12 OUTPUT 'Start year must be before 2000'
13 ELSE
14 validChoice ← True
15 ENDIF
16 ENDIF
17 UNTIL validChoice = True
18 difference ← endYear - startYear
19 OUTPUT difference
Complete the table to show what the values of the validChoice and difference variables would be for the given test data after the program finishes.
Figure 10 shows part of an algorithm that has been written in pseudo-code. There is an error in the algorithm.
The algorithm should:
- get the start year and end year from the user
- check that the start year is before the end year
- check that the start year is before 2000
- calculate the difference between the two years after a valid start year has been entered.
Figure 10
1 validChoice ← False
2 REPEAT
3 difference ← -1
4 OUTPUT 'Enter a start year '
5 startYear ← USERINPUT
6 OUTPUT 'Enter an end year '
7 endYear ← USERINPUT
8 IF startYear >= endYear THEN
9 OUTPUT 'Start year must be before end year'
10 ELSE
11 IF startYear < 2000 THEN
12 OUTPUT 'Start year must be before 2000'
13 ELSE
14 validChoice ← True
15 ENDIF
16 ENDIF
17 UNTIL validChoice = True
18 difference ← endYear - startYear
19 OUTPUT difference
Complete the table to show what the values of the validChoice and difference variables would be for the given test data after the program finishes.
How to approach this question
Full Answer
Common mistakes
Practice the full AQA GCSE Computer Science Paper 1 Python
31 questions · hints · full answers · grading
Expert