Skip to content

Course home

Sign up

Develop code

EasyMediumHard
1234567891011121314151617
Question 13

A program is required to calculate the total shipping cost for commercial cargo. Shipments are processed either as standard parcels or as bulk liquid cargo.

The user enters the number 50 if the shipment is for standard parcels, or the number 60 if the shipment is for bulk liquid cargo. The user then enters either the number of parcels (an integer) or the liquid cargo volume in cubic meters (a real number).

The program checks for invalid input. If the input is valid, the program calculates and displays the total shipping cost.

Currency formatting with two decimal places and a currency symbol is not required.

Table 1: Test cases and expected outputs

Cargo categoryParcel countLiquid volumeOutput
504Total cost is 61.6
500Invalid number of parcels
602.5Total cost is 281.25
60-3.2Invalid volume
55Invalid cargo type

Open file Q03.py which contains the following skeletal code:

# TODO: create an integer variable named cargoType and set it to 0

PARCEL_RATE = 15.40
LIQUID_RATE = 112.50

cargoType = int(input("Enter cargo type (50 or 60): "))

if cargoType != 50 [operator] cargoType != [constant]:
    print("Invalid cargo type")
else:
    if cargoType == 50:
        count = int(input("Enter number of parcels: "))
        if [check for 0 or negative count]:
            print("Invalid number of parcels")
        else:
            total = count * PARCEL_RATE
            print("Total cost is " + str(total))
    elif cargoType == [constant]:
        volume = [accept a real value for volume]
        if volume [relational operator] 0:
            print("Invalid volume")
        else:
            total = [calculate total cost based on liquid volume]
            # TODO: add a line to display an informative message and the total cost

Amend the code to:

  • Create an integer variable named cargoType and set it to 0.
  • Complete a line with the correct logical operator and the correct constant.
  • Complete a line with the correct constant.
  • Complete a line to accept a real (float) value for the liquid cargo volume.
  • Complete a line to calculate the total shipping cost based on bulk liquid volume.
  • Complete a line to check for a 0 or negative parcel count.
  • Complete a line with the correct relational operator.
  • Add a line to display an informative message and the total shipping cost.

Do not add any additional functionality.

Save your amended code as Q03FINISHED.py

[10]
Markscheme

Develop code Questions

  1. GCSE
  2. /Computer Science
  3. /Develop code

51 exam-style questions on Edexcel GCSE Computer Science Develop code, covering Decomposition and abstraction to solve problems, Read, write, analyse and refine programs, Converting algorithms into programs, Techniques for readable, maintainable code, Identifying and correcting program errors, and Evaluating program fitness and efficiency. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank