Pull it togheter


#1



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

Oops, try again. trip_cost('Pittsburgh', 0) returned 402 instead of the correct value 222

always I run the code I got a error message with new values 402 or 835 or moreI dont know what is the problem with the math

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 = 40 * days - 50
    elif days >= 3:
        cost = 40 * days - 20
    return cost
def trip_cost(days, city):
     return  hotel_cost(1) +  rental_car_cost(1) + plane_ride_cost("Pittsburgh")


#2

look at this code:

# function call with parameter days and city
def trip_cost(days, city):
     print days, city

# function call
trip_cost('Pittsburgh', 0)

your functions has 2 parameters: city and days, when you then call the function, you supply arguments to satisfy the parameters

this means, you can call the function multiply times with different arguments.

but then inside your function, you should use the function parameters, not fixed numbers

if you need a reminder about function arguments and parameters, revisit track 7. functions


#3

At the very end of the:

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

Go ahead and replace the 1s and "Pittsburgh" with the arguments of each variable that was defined earlier. However, instead of nights, use days for hotel_cost.


#4

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