Taking a Vacation - Lesson 6: Oops, try again. trip_cost('Charlotte', 5, 10) returned 1113 instead of the correct value 1073


#1



https://www.codecademy.com/en/courses/python-beginner-P5YtY/1/5?curriculum_id=4f89dab3d788890003000096

I did the calculations myself and the function returns the correct values. I'm not sure wht I keep getting errors similar to the below:
Oops, try again. trip_cost('Charlotte', 5, 10) returned 1113 instead of the correct value 1073

Can someone please take a look at my code and advise? I know that there is a very similar post to mine, but that is for the previous exercise, where we don't have the additional variable spending_money.
Thanks!


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 =40*days
    if days>=7:
        cost-=50
    elif days>=3 and days<7:
        cost-=20
    return cost
def trip_cost(city, days, money):
    spending_money=money*days
    return plane_ride_cost(city)+hotel_cost(days)+rental_car_cost(days)+spending_money
print ("The hotel cost for 7 days is: ", hotel_cost(7))
print ("The plane ride to Pittsburgh costs: ", plane_ride_cost("Pittsburgh"))
print ("The cost of renting a car for 7 days is: ", rental_car_cost(7))
print ("Your trip will cost you ", trip_cost("Pittsburgh", 7, 110), "if spending 110/day")


#2

you should modify your last function to be:
def trip_cost(city, days, spending_money):
return rental_car_cost(days) + plane_ride_cost(city) + hotel_cost(days) + spending_money

the spending_money is just one lump sum so it should directly be in the argument already, no need to multiply it by the number of days.


#3

I wanted to have a 'spending budget' per day and calculate how much spending money I will need for x days but I followed your instructions and I got to the next lesson.
Thanks for your help.


#4

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 "Los Angeles" :
return 475
else:
return 0
def food_cost(days):
cost==60*days
if days>=5 and days<=8:
return cost
else:
cost==50*days
def travel_cost(days):
cost==20*days
if days>=5 and days <=8:
return cost
else:
cost==15*days
return hotel_cost(nights)+plane_ride_cost(city)+food_cost(days)+travel_cost(days)
Please help me out


#5

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