# Hey, You Never Know!

#1

What did i do wrong?

"Oops, try again. trip_cost('Los Angeles', 2, 0) raised an error: global name 'city' is not defined"

``````def hotel_cost(nights):
return 140.0 * 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):
cost = days * 40
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
return cost

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 spending_money(place):
if city == "Charlotte":
return 123
elif city == "Tampa":
return 124
elif city == "Pittsburgh":
return 125
elif city == "Los Angeles":
return 126

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

print trip_cost``````

#2

problem1
`plane_ride_cost(city)`
repeated twice ?

**hint
delete one of them

problem2

what instruction said to do ?
you did not needed to build this function..

``````def spending_money(place):
if city == "Charlotte":
return 123
elif city == "Tampa":
return 124
elif city == "Pittsburgh":
return 125
elif city == "Los Angeles":
return 126``````

spending_money is a parameter that has to be passed to `trip_cost` function!
(you passed place as parameter to trip_cost() function?)

problem3
also your trip_cost function needs arguments while you call it and print it.

#3

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

#4

Please read the community guidelines, posting code with no explanation is prohibited

@greentreemee was already assisting the user.

#5

point taken sir, i won't do it again

#6

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