Pull it together


#1

hello I would appreciate a little help on this I seem to have done everything right again!!


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
    else: 
        return 475
def rental_car_cost(days): 
    cost = 40 * days
    if days >= 7:
        cost -= 50
    elif days >= 3:
        cost -= 20
    else:
        cost
    return cost    

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


#2

@sckallywags ,

What happened to the order of the parameters, here? ...

def  trip_cost(days,city):

Codecademy tests your function based on the assumption that the parameters are in the order, city, followed by days.

Also note that this else block serves no purpose ...

else:
    cost

#3

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


#4

Codecademy expects the trip_cost function header to contain the parameters in a specific order, as follows ...

def trip_cost(city, days):

The code will not pass Codecademy's submission correctness test (SCT), if the parameters that are used to represent the city and the number of days are in a different order.


#5

help me i need help give me a all of it


#6

i need help to
:frowning:


#7

So in my case, the issue was that it only allowed two arguments, meaning I could not include the last piece to the cost. So, in place of this, I simply used the argument days in place of nights, and multiplied it by 140. That way, since days and nights are practically the same thing, it will pull up the same answer. Here is my code.

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 > 6:
return cost - 50
elif days > 2:
return cost - 20
return cost

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

Make sure to indent the code if the editor didn't do it for you!
Hopefully this helps. :slight_smile:


#8

This worked for me:

def hotel_cost(days):
return days * 140

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
else:
return 'Unknown destination'

def rental_car_cost(days):
rental_car_cost = days * 40
if days < 3:
return rental_car_cost
elif days >= 3 and days < 7:
return rental_car_cost - 20
elif days >= 7:
return rental_car_cost - 50
def trip_cost(city,days):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)

Hope it works...


#9

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