Where am I going wrong?


#1

Can anyone help me here? Where am I going wrong?

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 = days * 40
    if days >= 7:
       cost -= 50
    elif days >= 3:
       cost -= 20
    return cost 

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

Pull it Together
#2

Do the instructions say, (city, days)? If so, that is what will be expected. The SCT will try to run,

trip_cost("Tampa", 3)

and it will fail since the function will see a string in days and a number in city.

The order that we write the parameters is inconsequential, but the order we call the function with will directly match the order of the params, not the variables.

def func(a, b):
    return a if ord(a) > b else b

func(96, "a")

This will raise an exception since 95 is not a character, but a number.


#4

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