This is problem part of my assesment I've done but my assesment says use a function to calculate the fuel cost and function should take 3 parameters : distance,economy(as litres per 100 kms) , and fuel price per litre. The function should return the total cost of trip. Could you please help me out with this ,,,

'''Calculate the cost of fuel for a road trip'''
def main():
distance = float(raw_input("Enter distance in
kilometres: "))
litresPer100K = float(raw_input("Enter economy (ltr/
100km): "))
pricePerLitre = float(raw_input("Enter fuel price per
litre ($): "))
cost = distance / 100 * litresPer100K * pricePerLitre
print "Fuel cost is $%0.2f" % cost
main()

Any help Appreciated !!!

Edited 6 Years Ago by lebron: n/a

All you have to do is to take the line
cost = distance / 100 * litresPer100K * pricePerLitre
and put it into a function like
def calculateCost(distance, litresPer100K, pricePerLitre):
the function has to return cost

Now in function main() replace the line
cost = distance / 100 * litresPer100K * pricePerLitre
with
cost = calculateCost(distance, litresPer100K, pricePerLitre)

All you have to do is to take the line
cost = distance / 100 * litresPer100K * pricePerLitre
and put it into a function like
def calculateCost(distance, litresPer100K, pricePerLitre):
the function has to return cost

Now in function main() replace the line
cost = distance / 100 * litresPer100K * pricePerLitre
with
cost = calculateCost(distance, litresPer100K, pricePerLitre)

Thanks alot man really appreciate for your time , it helped me out .

cheers !!!

This article has been dead for over six months. Start a new discussion instead.