Easy1 markExtended Response
ProgrammingGeneralrobustnessvalidationpython

AQA GCSE · Question 04.2 · Programming

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