Pull it together


#1

Don't know whats wrong with 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

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

print trip_cost("Charlotte", 6, 700)

#2

Here is an example of what you last two lines could look like.

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

Also, I am not sure your rental_car_cost method is correct mathematically:

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

#3

I didn't notice i don't need spending_money in this lesson. It works now. Thanks a lot


#4

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