Figure 1 shows a Python program that calculates the total cost of a hotel stay.
# Figure 1
def calculate_stay(nights, room_rate, meal_plan):
if meal_plan == 0:
return nights * room_rate
else:
return (nights * room_rate) + (nights * 25)
num_nights = int(input("Enter number of nights: "))
rate = int(input("Enter room rate per night: "))
breakfast = int(input("Enter 1 for breakfast, 0 for room only: "))
total_cost = calculate_stay(num_nights, rate, breakfast)
print("Total cost of stay is: £" + str(total_cost))
Describe one way that the program in Figure 1 could be made more robust.
27 exam-style questions on AQA GCSE Computer Science Robust and secure programming. Each one has a worked solution and a mark scheme showing where the marks go.