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.
| Cargo category | Parcel count | Liquid volume | Output |
|---|---|---|---|
| 50 | 4 | Total cost is 61.6 | |
| 50 | 0 | Invalid number of parcels | |
| 60 | 2.5 | Total cost is 281.25 | |
| 60 | -3.2 | Invalid volume | |
| 55 | Invalid 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:
cargoType and set it to 0.Do not add any additional functionality.
Save your amended code as Q03FINISHED.py
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.