What is wrong with my code? Please help


#1

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

I keep getting this error: Oops, try again. trip_cost should take exactly three parameters: city, days, and spending_money (in that order).


def hotel_cost(days):
    return 140 * days
    
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):
    if days > 0 and days < 3:
        return days * 40
    elif days >= 3 and days < 7:
        return days * 40 - 20
    elif days >=7:
        return days * 40 - 50
    else:
        return 0  
    
def trip_cost(city, days, spending_money):
    return plane_ride_cost(city) + rental_car_cost() + hotel_cost(days) + spending_money
        
    print trip_cost("Los Angeles", 5, 600)


#2

Suggest get rid of excessive logic. Think this one through in simplest terms.

Given A, B, C, and,

A > B

B > C

Therein lies the hint.

days > 6
days > 2

Using if..elif..else we trap these two conditions and apply the discount accordingly.


#3

Thank you mtf for the suggestions. It helped!


#5

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