Answer:
weight1 = float(input("Enter the weight of first package: "))
price1 = float(input("Enter the price of first package: "))
weight2 = float(input("Enter the weight of second package: "))
price2 = float(input("Enter the price of second package: "))
if weight1 > 0 and price1 > 0 and weight2 > 0 and price2 > 0:
unit_cost1 = price1 / weight1
unit_cost2 = price2 / weight2
if unit_cost1 < unit_cost2:
print("Package 1 has a better price.")
else:
print("Package 2 has a better price.")
else:
print("All the entered values must be positive!")
Explanation:
*The code is in Python.
Ask the user to enter the weight and the price of the packages
Check if the all the values are greater than 0. If they are, calculate the unit price of the packages, divide the prices by weights. Then, compare the unit prices. The package with a smaller unit price has a better price.
If all the entered values are not greater than 0, print a warning message