School Trip Bus Quote

school-busA school teacher is organising a school trip for the whole year group. He expects between 250 and 350 students to attend this trip. To estimate the cost of the trip, the school teacher has contacted a coach company to hire several coaches for a day.

The coach company has two categories of buses:

Bus Number of seats Cost per day
school-bus-sign Large Bus 46 Seats £360
school-mini-bus-sign Small Bus 16 Seats £140

The school teacher would like a computer program that will:

  1. Ask for the number of students taking part in the trip.
  2. Ask for the number of teachers taking part in the trip.
  3. Calculate the total number of participants (by adding the number of students and the number of teachers).
  4. Find out and output the number of large coaches that will be required.
  5. Find out and output the number of small coaches that will be required.
  6. Calculate and output the total cost of the hiring these coaches for a day.

Flowchart


Here is the flowchart for this algorithm:
school-trip-bus-quote-flowchart

Python Code


Your task is to use the above flowchart to complete the Python code below:

Testing


Once your code is done, complete the following tests to check that your code is working as it should:

Test # Input Values Expected Output Pass/Fail?
#1 Number of students: 250
Number of teachers: 7
Number of large buses: 5
Number of small buses: 2
Total cost: £2080
#2 Number of students: 300
Number of teachers: 10
Number of large buses: 6
Number of small buses: 3
Total cost: £2580
#3 Number of students: 350
Number of teachers: 12
Number of large buses: 7
Number of small buses: 3
Total cost: £2940
#4 Number of students: 0
Number of teachers: 0
Number of large buses: 0
Number of small buses: 0
Total cost: £0

Extension Task #1


You have noticed that it is more cost effective to hire a large bus (£360) instead of three small buses (3 * £140 = £420) even if the large bus is not full.
So your task is to adapt the above algorithm so that, when calculating the number of large buses, if the number of pupils left (remainder) is greater than 32, your program will hire one extra large bus instead of 3 small buses. It will hence output the most cost effective solution for test #2 and test #3.

The new test plan would be as follows:

Test # Input Values Expected Output Pass/Fail?
#1 Number of students: 250
Number of teachers: 7
Number of large buses: 5
Number of small buses: 2
Total cost: £2080
#2 Number of students: 300
Number of teachers: 10
Number of large buses: 7
Number of small buses: 0
Total cost: £2520
#3 Number of students: 350
Number of teachers: 12
Number of large buses: 8
Number of small buses: 0
Total cost: £2880
#4 Number of students: 0
Number of teachers: 0
Number of large buses: 0
Number of small buses: 0
Total cost: £0

Extension Task #2


To make your program more robust, you can add some validation checks on both inputs. These validation checks will ensure that the user can only input whole numbers (integers). To do so, you should check the following blog post: number only validation in Python.

Share Button
Tagged with: