Why should a programmer use a constant instead of a variable to store the value of pi (3.14159)?
A Constants are stored faster by the CPU
B Constants use less memory than variables
C Pi should never change during the program — using a constant prevents accidental modification and if the value ever needs updating, only one change is required
Describe the difference between a FOR loop and a WHILE loop. Give an example situation where each would be most appropriate. (4 marks)
Hint: Cover: how each loop is controlled (count vs condition) + when each is appropriate. Two marks per loop type.
+40 XP
2 marksError type identificationPaper 1 · spec 1.2.5 (1CP2 Jun 2024 Q1(d)(ii) style)
A program contains the following code: result = 10 / userInput
Explain what type of error occurs if the user enters 0, and why the program behaves as it does. (2 marks)
Hint: Name the error type (runtime) AND explain WHY — what makes this impossible for the CPU to execute.
+20 XP
1 markValidationPaper 2 · spec 6.4.3
A program rejects any password with fewer than 8 characters. Which validation check is this?
A Presence check
B Length check
C Range check
D Pattern check
3 marksRange check in PythonPaper 2 · spec 6.4.3
Write Python that asks for an age and keeps asking until the age entered is from 11 to 16 inclusive. (3 marks)
Hint: Convert the input to a number, then loop while the age is outside the range.
+30 XP
3 marksAuthenticationPaper 2 · spec 6.4.4
The lists ids = ["ava", "ben"] and passwords = ["tiger", "lion"] hold the users, so passwords[0] belongs to ids[0]. Describe, or write the Python for, a log-in check that grants access only to a valid ID and password. (3 marks)
Hint: Ask for both, find the position of the ID, compare the matching password.
+30 XP
1 markReadabilityPaper 2 · spec 6.1.4
Which of these makes a program easier to read and maintain?