Hi
I am struggling with oulling it all together. i am sure i need to double the days. but the Def creates a problem. can someone point out what i am doing incorrectly.

My code is below

def hotel_cost(nights):
costs = 140*nights
print costs
return hotel_cost(5)
def plane_ride_cost(city):
if city == "Charlotte":
return 183
elif city == "Tampa":
return 220
elif city == "Pittsburgh":
return 222
elif city == "Los Angeles":
return 475
print plane_ride_cost(Tampa)
def rental_car_cost(days):
costs = 40*days
if days >= 7:
costs -=50
elif days >=3:
costs -=20
return costs
def trip_cost(city, days):
def double(days):
return 2 * days
def trip_cost (a, b):'
return double(a) +city("Charlotte")

because we are asked to only to apply only two arguments ( city and days.) when there are three facets. The days and nights are the sae. plus they introduce the concept of doubling in the exercise- i presume for the reason for me to apply it??

Hmm, I will try to clarify it a little bit. This example with double is for showing you, that you can pass argument from one function to another.

def add(a, b):
return double(a) + triple(b)

here we have func add, which takes arguments a and b, and in return we pass argument a to function double.
In our excercise it means, that def trip_cost takes two arguments: city and days but in return it suppose to give sum from three values.

From instruction: â€śLike the example above, have your function return the sum of calling the rental_car_cost(days), hotel_cost(days), and plane_ride_cost(city) functions.â€ť and that is how your function should look like. Example is only to show you, that you can use argument days and pass it to def hotel_cost(nights)

You really are doing too much, you do not need all that fancy foot work to accomplish this section.

city_prices = {
"Charlotte": 183,
"Pittsburgh": 222,
"Tampa": 220,
"Los Angeles": 475
}
def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
try:
return city_prices[city]
except KeyError:
print("Not a valid destination.")
def rental_car_cost(days):
if days >= 7:
return days * 40 - 50
elif days >= 3:
return days * 40 - 20
return days * 40
def trip_cost(city, days):
return hotel_cost(days) + rental_car_cost(days) + plane_ride_cost(city)

As you can see from my codebit here, they want you to build a function that takes city and days. So just build the function there, it then passes the given arguments to the hotel cost, rental car and plane ride functions, finally adding the totals together.

I can understand how you arrived at what you did though as this course is not written in an orderly fashion. Parts of it can be confusing.

Great! You can shorten your code little bit by changing [quote=â€śstephaniebudlender, post:6, topic:18684â€ť]
total = rental_car_cost(days)+ hotel_cost(days) + plane_ride_cost(city)
return total
[/quote]
into just return rental_car_cost(days)+ hotel_cost(days) + plane_ride_cost(city)

@zeziba great idea with using dictionary instead if for city_prices

Personally I thought they were going backwards when they asked us to put it all in a function, if you were to actually build something like this you would use a database or other persistent data to store all the locations. Then you would just search through it to get what you wanted.

I also think they should adjust this course as such but that is not likely to happen.

for the function rental_car_cost(days), i think the condition should be like :
def rental_car_cost(days):
if days <3:
return 40 * days
elif days >=3 and days <7:
return (40 * days) - 20
elif days>=7 :
return 40*days-50