Cant "pull it together" on 5/7


#1



I'm on 5/7 Pulling it together where you add Hotel_costs, plane_ride_costs, and rental_car_costs.


It doesnt appear to be summing the hotel_costs and rental_car_costs properly

Oops, try again. trip_cost('Tampa', 4) returned 220 instead of the correct value 920


it should have added them up. The functions have all worked individually but dont seem to work together.


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 'Wrong'

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

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


#2

There is no requirement for an else statement in either function. Python will return None.

Should have a days parameter.

The above will work, though it could be simplified.

    cost = days * 40
    if days >= 7:
        cost -= 50
    elif days >= 3:
        cost -= 20
    return cost

#3

oh thank you it was just that i used day instead of days. I didnt think of simplifying the rental_car_cost that way.


#4

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