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.