# Taking a vacation(print out)

#1

i can't get my code to print out the trip cost
keeps saying, my code is a bit off

def hotel_cost(nights):
return 140 * nights
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

def rental_car_cost(days):
total = days * 40
if(days >= 7):
total -= 50
elif(days >= 3):
total -= 20
def trip_cost(city, days, spending_money):
return rental_car_cost(days)+hotel_cost(days)+plane_ride_cost(city)+spending_money

``print trip_cost("Los Angeles", 5, 600)``

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
def rental_car_cost(days):
rent = 40 * days
if days >= 7:
rent = rent - 50
elif days >= 3:
rent = rent - 20
return rent
def hotel_cost(days):
return 140 * days

def trip_cost(city, days, spending_money):
return plane_ride_cost(city) + hotel_cost(days) + rental_car_cost(days) + spending_money
print trip_cost("los Angeles", 5, 600)

#2

If the exersice is "Pull it together" i find it.
As first, you don't have to add spending_money to the trip cost, so it looks like this

def trip_cost(city, days):
return rental_car_cost(days) + plane_ride_cost(city) + hotel_cost(days)

def trip_cost(city, days, spending_money):
return plane_ride_cost(city) + hotel_cost(days) + rental_car_cost(days) + spending_money
print trip_cost("los Angeles", 5, 600)

rental_car_cost is a different thing. You must just use one if (and an elif) to check the day, and then count number of times multiplied by 40 and remove the discount.

def rental_car_cost(days):
if days >= 7:
return (40*days) - 50
elif days >= 3:
return (40*days) - 20
else:
return 40*days

Voela!

And see? The output is correct!

#3

Also note that here, the argument you passed for the `city` begins with a lowercase letter, and therefore, the function call will return the value, `None` ...

``print trip_cost("los Angeles", 5, 600)``

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.