3Easy
0/1

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.

[1]

Robust and secure programming Questions

Practise AQA GCSE Computer Science Robust and secure programming with exam-style questions for GCSE Computer Science. 28 questions, matched to the AQA GCSE Computer Science (8525) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.

PreviousNext

Robust and secure programming Questions

  1. GCSE
  2. /Computer Science
  3. /Robust and secure programming