Question 1[4 marks]
Zara has created the following program in her computer science lesson. The aim of this program is to find out if the user is old enough to vote or not, the voting age being 18 years old. If the user is too young to vote, the program will calculate and output in how many years the user will be allowed to vote!Here is her Python code:
#Voting Age Checker a = int(input("How old are you?")) if a<=18: print(You can vote!") else: y = 18 - a print("You will be allowed to vote in " + str(y) + " years!")
Zara made two errors in her code. A syntax error and a logic error. Identify these two errors and explain how these could be fixed.
Syntax Error:
Logic Error:
Logic Error:
Question 2[2 marks]
Explain the difference between a logic error and a syntax error.
Question 3[3 marks]
In order to test her program, Zara is designing a test plan. She wants to use specific input values to complete three types of tests:
- Normal/Valid Test
- Boundary/Borderline/Extreme Test
- Erroneous Test
- Valid/Normal Test Data:
- Boundary Test Data:
- Erroneous Test Data:
Question 4[2 marks]
Identify two purposes of testing.
Question 5[2 marks]
Identify two ways, Zara could use to make her code easier to understand and maintain.
Question 6[5 marks]
Zara would like to create a function using her code. The function should be called checkVotingAge(). It should
- take one parameter (the age of the user as an integer value),
- output the messages as it currently does
- return a Boolean value as to whether the user is allowed to vote or not.
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area