Pull it Together


#1



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


Oops, try again. rental_car_cost(3) returned None instead of the correct value 100


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:
        cost-=20
    else:
        40*cost
        return cost
def trip_cost(city,days):
    return hotel_cost(nights)+rental_car_cost(days)+plane_ride_cost(city)


#2

Hi @rajat6151,

Reconsider the indentation of this statement in the rental_car_cost function ...

return cost

You have it part of the else block. As a result, if one of the other blocks executes, None is returned.

Also consider whether this statement is adequate or even necessary ...

40*cost

Do you really need the else block at all?


#3

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