A school billing system uses the following Python-style program to calculate the total fee for a field trip based on a base ticket price, the number of tickets, and optionally a food package cost (-1 if no food package).
def calculate_fee(tickets, price, food_cost):
if food_cost == -1:
return tickets * price
else:
return (tickets * price) + food_cost
# Main
print("Enter number of tickets:")
num_tickets = int(input())
print("Enter ticket price:")
ticket_price = int(input())
print("Enter food package cost (-1 to ignore):")
food_charge = int(input())
total = calculate_fee(num_tickets, ticket_price, food_charge)
if food_charge == -1:
print("Total charge (excluding food): " + str(total))
else:
print("Total charge (including food): " + str(total))
Describe one way that this program 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.