0

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 by lebron: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by lebron
0

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)

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.