I can’t understand what i’m doing wrong. I’m trying to follow the forums but it isn’t really helping. Here’s my code.
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
else:
return “None”
def rental_car_cost(days):
cost = 40 * days
if days >= 7:
return cost - 50
elif days in range(3, 7):
return cost - 20
else:
return cost
def money(spending_money):
return spending_money
def trip_cost(city, days,spending_money):
return plane_ride_cost(city) + hotel_cost(days) + rental_car_cost(days) + money(spending_money)
You don’t need to define the money function! just add spending_money to your last term.
but now i got this
trip_cost(‘Tampa’, 4, 0) raised an error: global name ‘money’ is not defined
here is the code
if city== “Charlotte” :
return 183
elif city== “Tampa” :
return 220
elif city== “Pittsburgh” :
return 222
elif city== “Los Angeles” :
return 475
else:
return “None”
def rental_car_cost(days):
cost = 40 * days
if days >= 7:
return cost - 50
elif days in range(3, 7):
return cost - 20
else:
return cost
def trip_cost(city, days,spending_money):
return plane_ride_cost(city) + hotel_cost(days) + rental_car_cost(days) + money(spending_money)
here is my code, but I get the “trip_cost should take exactly three parameters: city, days, and spending_money (in that order).” error in 7/7 section, while my code is working!
def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
if city == “Charlotte” :
return 183
if city == “Tampa” :
return 220
if city == “Pittsburgh” :
return 222
if city == “LosAngeles” :
return 475
def rental_car_cost(days):
if days >= 7:
return (40 * days)-50
elif days >=3:
return (40 * days)-20
else:
return 40 * days
def trip_cost(city, days, spending_money):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money
i see. thank you for the help
The bulk of the code is correct. There’s just a few minor tweaks that is needed.
For example: when writing it “city==” it’s best to have a space: “city ==”
Also, you need to make sure that your use “print” instead of return on the last line. Otherwise, Codecademy is going to assume that you got the code wrong. Here is my code which works perfectly fine:
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):
cost = days * 40
if days >= 7:
return cost - 50
elif days >= 3:
return cost - 20
return cost
def spending_money(extra):
return extra
def trip_cost(city, days, extra):
return rental_car_cost(days) + hotel_cost(days -1) + plane_ride_cost(city) + spending_money(extra)
return trip_cost
print trip_cost("Los Angeles", 5, 600)