i have been working on this code

'''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()

now this works but i need to include how to calculate the cost of fuel for each trip.

i am unsure how to approach this

any suggestion or help would be great

.... dont no how much longer i can look at this :(

Do you want to do several road trips and keep petrol price and economy the same?

I need to calculate the fuel cost for a whole trip with keeping the three parameters (distance, econome and the price of fuel ) changeable

I need to calculate the fuel cost for a whole trip with keeping the three parameters (distance, econome and the price of fuel ) changeable

Maybe use parameters in the function like this (pseudo code)

def roadtrip(what1,what2 etc):
#no inputs, no prints
     #do my calculation
     return result_of_my_calculation

#instead of main()
total=0.0
#repeat
#  raw inputs from your function
cost=roadtrip(given values)
print "Fuel cost is $%0.2f" % cost
#add to total and print it also
#and finish when user wants to

I don't understand what you are doing wrong?

Are you looking for a function?

def calculatefuel(distance, economy, price):
    return distance / 100 * economy * price

from the code that ive written above i need to calculate the the cost of fuel for a trip
after a user has entered in the cost of fuel , economy of the car and the length of the trip

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.