Write a program in python to calculate the charges for a parcel, taking the weight of the package as input. The charges are as follows:
For the first 1kg, rates are rs.15. For the additional weight(For every 500 g), rates are rs.8
Plzz help
I will mark it as brainliest
Answers
Answer:
assuming that weight is expressed in grams
l=int(input("Enter weight of parcel :"))
cost=15
if l==1000:
print("cost of parcel is rupees",cost)
elif l>1000:
print("cost is rupees",cost+8)
To calculate the charges for a parcel in Python, you can use the following program:
- Create a variable to store the weight of the package in kilograms.
- Create a variable to store the base rate of rs.15 for the first 1kg.
- Use an if statement to check if the weight of the package is greater than 1kg.
- If it is, calculate the additional weight by subtracting 1kg from the total weight.
- Divide the additional weight by 0.5 to determine the number of 500g increments.
- Multiply this number by the additional rate of rs.8 per 500g increment.
- Add this amount to the base rate to get the total charges for the package.
- Print the total charges for the package.
# Input weight of package in kilograms
weight = float(input("Enter the weight of the package in kilograms: "))
# Base rate for first 1kg
base_rate = 15
# Additional rate for every 500g
additional_rate = 8
# Check if weight is greater than 1kg
if weight > 1:
# Calculate additional weight
additional_weight = weight - 1
# Calculate number of 500g increments
increments = additional_weight / 0.5
# Calculate additional charges
additional_charges = increments * additional_rate
# Calculate total charges
total_charges = base_rate + additional_charges
else:
# If weight is less than or equal to 1kg, only base rate is applicable
total_charges = base_rate
# Print total charges
print("Total charges: Rs." + str(total_charges))
Note:
- The program assumes that the weight of the package is given in kilograms.
- The program rounds up additional weight to next 500g.
- The program doesn't consider any weight above 20 kg.
- The program doesn't handle any errors that might occur if the weight of the package is not a number.
To learn more about python from the given link.
https://brainly.in/question/16086632
#SPJ3