Easy1 markExtended Response
AQA GCSE · Question 04.2 · Programming
Describe one way that the program in Figure 3 could be made more robust.
Describe one way that the program in Figure 3 could be made more robust.
How to approach this question
Think about what could go wrong when the user is asked for input. What happens if they type text instead of a number? What if they enter a negative number for a dimension? A robust program anticipates and handles these potential errors.
Full Answer
The program could be made more robust by adding input validation. For example, it could check if the user enters a non-numeric value and handle the error gracefully instead of crashing. It could also check for negative inputs for width and length, which are not physically possible.
A robust program is one that can handle unexpected or invalid inputs without crashing. The current program in Figure 3 is not very robust. If a user enters text (e.g., "five") instead of a number, the `int()` function will raise a `ValueError`, and the program will crash.
A way to make it more robust is to add **input validation** using a `try-except` block. This allows the program to "try" to convert the input to an integer and "catch" the error if it fails, prompting the user to enter a valid number instead of crashing.
Example of robust input:
python
try:
numOne = int(input("Enter width: "))
except ValueError:
print("Invalid input. Please enter a number.")
Common mistakes
✗ Suggesting a change that doesn't relate to robustness (e.g., changing the output message).\n✗ Being too vague (e.g., "add error handling") without specifying what kind of error to handle.
Practice the full AQA GCSE Computer Science Paper 1 Python
31 questions · hints · full answers · grading
More questions from this exam
Q01.1Figure 1 shows an algorithm, represented using pseudo-code, which assigns a different value to fo...EasyQ01.2The variable `x` is assigned a value using the statement:
`x ← LEN(state)`
Using Figure 1, what ...EasyQ01.3What is the result of concatenating the contents of the variables `city` and `landmark` in Figure 1?EasyQ01.5The subroutine `POSITION` finds the first position of a character in a string.
For example, `POSI...EasyQ02.1Figure 2 shows an algorithm that uses integer division which has been represented using pseudo-co...Easy
Expert