Incorrect math/logic in "Pull it Together"


The code's math is incorrect. This is the passing code.

The final line should be:

return plane_ride_cost(city) + hotel_cost(days - 1) + rental_car_cost(days)

This is because you aren't paying for the last night during the trip.

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
        return "nope"

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

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


And what about handling an invalid city input?

There are so many things which can be improved on this program, codecademy gives you the basic, you can then improve up on the program


No, there is error handling in the program for dealing with bad city inputs.

Clearly this isn't the most advanced program, I will grant that. But the lesson should at least encourage critical thinking and use appropriate logic. You don't even have to force users to think of it themselves, just add it in the instructions.


critical thinking is always highly encouraged, i would also encourage to expand the program


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