Study notes
No notes have been generated for this topic yet. Open the topic page online and click Generate notes first.
Past exam questions (12)
2022 · Part C · Q16(a)(vii) · p.6
Amend the program to deal with invalid number entries. If the user enters any number other than the numbers 1, 2 or 3 they should be presented with an error message. When the program is run the output may now look as follows: Enter the number of the item you would like: 5 Invalid choice. Goodbye. Save your file using the format ExaminationNumberQuestion16_A.py. For example, you would save the file as 123456Question16_A.py if your Examination Number was 123456.
2022 · Part C · Q16(a)(vi) · p.6
Amend the program so that the correct message is printed if the user purchases a ruler or pen. When the program is run the output may now look as follows: Enter the number of the item you would like: 2 You bought a ruler
2021 · Part A · Q1 · 30 marks · p.3
Choose the appropriate Python data type from the following list and place it in Column B to match the variable assignments in Column A. Float Boolean Integer String List [Table: Column A shows variable assignments: a = 5, b = "Hello World", c = True, d = ["apple", "banana", "orange"], e = 2.718. Column B is for Data Type.]
2021 · Part C · Q16(a)(vii) · p.4
The user should only be allowed 3 failed login attempts. If the PIN is entered incorrectly 3 times an appropriate message should be displayed. When the program is run the output may look as follows: Enter PIN:1111 Incorrect PIN Enter PIN:2222 Incorrect PIN Enter PIN:3333 Incorrect PIN You have entered the PIN incorrectly 3 times.
2021 · Part C · Q16(a)(vi) · p.4
Create a suitably named variable (e.g. failedAttempts) that is initially set to 0 before the user enters a PIN. This variable will keep track of the number of failed login attempts.
2021 · Part C · Q16(a)(v) · p.4
Using a while loop or similar, keep asking the user to enter their PIN until they have entered it correctly. When the program is run the output may look as follows: Enter PIN:1234 Incorrect PIN Enter PIN:1456 Incorrect PIN Enter PIN:1579 Welcome
2021 · Part C · Q16(a)(iv) · p.3
Amend the program so that the new Boolean variable is set to True when the user enters the correct PIN.
2021 · Part C · Q16(a)(iii) · p.3
Create a suitably named Boolean variable (e.g. loggedIn) that is initially set to False before the user enters a PIN.
2021 · Part C · Q16(a)(ii) · p.3
Amend the program so that the following message is displayed if an incorrect PIN is entered: Incorrect PIN
2021 · Part C · Q16(a)(i) · p.3
Insert a comment in the appropriate location to explain what the input command is doing in this program.
2021 · Part C · Q16(a) · p.3
Open the program called Question16_A.py from your device. The source code is shown and described briefly below. Before making any changes, you should save your working copy of the file using the format CandidateNumberQuestion16_A.py. For example, you would save the file as 123456Question16_A.py if your candidate number was 123456. Enter your Examination Number in the space provided on line 2 in your Python file. The program below is for a simple Automatic Teller Machine (ATM). An ATM allows banking customers to withdraw money from their accounts provided they enter the correct Personal Identification Number (PIN). When the user enters the correct PIN, a message appears saying "Welcome". 1 # Question 16(a) 2 # Examination Number: 3 4 pin = "1579" 5 6 userTry = input("Enter PIN:") 7 8 if userTry == pin: 9 print("Welcome") Make the following changes to the program: (i) Insert a comment in the appropriate location to explain what the input command is doing in this program. (ii) Amend the program so that the following message is displayed if an incorrect PIN is entered: Incorrect PIN (iii) Create a suitably named Boolean variable (e.g. loggedIn) that is initially set to False before the user enters a PIN. (iv) Amend the program so that the new Boolean variable is set to True when the user enters the correct PIN.
2021 · Part A · Q9 · p.7
Complete the trace table below to determine the output of the following Python program after it has completed running. The first row of the trace table has been completed for you. 1 a = 1 2 b = 2 3 while (a < 4): 4 a = a + 1 5 b = b + a 6 7 print(b) [Table: Trace table with columns for Step, a, b, and a < 4. Row 1 is filled: Step 1, a=1, b=2, a < 4=True. Rows 2, 3, 4 are empty for a, b, and a < 4.] Output: