Answer:
weight = float(input("Enter the weight of the package: "))
distance = float(input("Enter the distance to be sent: "))
weight_charge = 0
if weight <= 2:
weight_charge = 0.25
elif 2 < weight <= 10:
weight_charge = 0.3
elif 10 < weight <= 20:
weight_charge = 0.45
elif 20 < weight <= 50:
weight_charge = 1.75
if int(distance / 100) == distance / 100:
d = int(distance / 100)
else:
d = int(distance / 100) + 1
total_charge = d * weight_charge
print("The charge is $", total_charge)
Explanation:
*The code is in Python.
Ask the user to enter the weight and distance
Check the weight to calculate the weight_cost for 100 miles. If it is smaller than or equal to 2, set the weight_charge as 0.25. If it is greater than 2 and smaller than or equal to 10, set the weight_charge as 0.3. If it is greater than 10 and smaller than or equal to 20, set the weight_charge as 0.45. If it is greater than 20 and smaller than or equal to 50, set the weight_charge as 1.75
Since those charges are per 100 miles, you need to consider the distance to find the total_charge. If the int(distance / 100) is equal to (distance / 100), you set the d as int(distance / 100). Otherwise, you set the d as int(distance / 100) + 1. For example, if the distance is 400 miles, you need to multiply the weight_charge by 4, int(400/100) = 4. However, if the distance is 410, you get the int(400/100) = 4, and then add 1 to the d for the extra 10 miles.
Calculate the total_charge, multiply d by weight_charge
Print the total_charge