Respuesta :
Answer:
The program in Python is as follows:
def getRate(weight):
if weight<=2.0:
rate = 1.10
elif weight>2 and weight<=6:
rate = 2.20
elif weight>6 and weight<=10:
rate = 3.70
else:
rate = 3.80
return rate
def getTotal(weight,rate):
total = weight * rate
print("Total: ",total)
weight = float(input("Weight: "))
rate = getRate(weight)
getTotal(weight,rate)
Explanation:
This defines the getRate function
def getRate(weight):
The following if conditions determine the corresponding rate based on the value of weight passed to the function
if weight<=2.0:
rate = 1.10
elif weight>2 and weight<=6:
rate = 2.20
elif weight>6 and weight<=10:
rate = 3.70
else:
rate = 3.80
This returns the rate back to the main method
return rate
The getTotal module begins here
def getTotal(weight,rate):
This calculates the total charges
total = weight * rate
This prints the calculated total
print("Total: ",total)
The main begins here
This gets input for weight
weight = float(input("Weight: "))
This gets the rate from the getRate function
rate = getRate(weight)
This passes values to the getTotal function
getTotal(weight,rate)