Skip to content

Course home

Develop code

Develop code

EasyMediumHard
1234567891011121314151617181920212223242526
Question 14

A developer is writing a program to validate and classify parcel weights according to a strict specification.

The expected outputs for different inputs are shown in the table below:

Input Weight (W)Output Message
Empty"Please enter a weight"
Less than or equal to 0"Weight must be positive"
1 to 15"Lightweight"
40 or more"Lightweight"
21 to 29"Medium"
20"Exact Target"
Any other number"No classification"

The following Python code was written to implement this, but it contains several logic errors and incorrect conditions:

weight_input = input("Enter parcel weight: ")

if weight_input == "":
    print("No classification")
else:
    weight = int(weight_input)
    if weight < 0:
        print("Weight must be positive")
    elif weight >= 1 and weight <= 15:
        print("Lightweight")
    elif weight > 40:
        print("Lightweight")
    elif weight >= 21 or weight <= 29:
        print("Medium")
    elif weight == 20:
        print("Exact Target")
    else:
        print("No classification")

Amend the code to ensure that all messages are displayed correctly according to the specification.

[6]
Markscheme

Develop code Questions

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

62 exam-style questions on Edexcel IGCSE Computer Science Develop code. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank