Skip to content

Course home

Robust and secure programming

Robust and secure programming

EasyMediumHard
123456789101112131415161718
Question 2

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]
Markscheme

Robust and secure programming Questions

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

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.

Question bank