6. Hey you never know


#1



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


Oops, try again. trip_cost('Charlotte', 7, 0) returned None instead of the correct value 1393

correct

Replace this line with your code. 

def hotel_costs(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):
    rental_cost = 40*days
    if days >= 7:
        return 40*days-50
    elif days >= 3:
        return 40*days-20
    else:
        return rental_cost
        
def trip_cost(city,days,spending_money):
    def spending_money(money):
        return rental_car_cost(days) + plane_ride_cost(city) + hotel_cost(days) + spending_money(money)


Pull it together
#2

This line should be the confusion. Needless.

:slight_smile:


#3

i took it out but i got this error now

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

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

Oops, try again. trip_cost('Tampa', 6, 0) raised an error: global name 'money' is not defined


#4

The error says: global name 'money' is not defined. And it is not defined.

You are to add spending_money to the return statement. It should take no parameter.


#5

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

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

got another error

Oops, try again. trip_cost('Tampa', 5, 0) raised an error: 'int' object is not callable


#6

No...you should just have:

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

#7

thanks!!! for everything


#8

You're welcome. Glad I could help.

Have fun coding! :slight_smile:


#9

i do same command as you show in your command line but still i have this error please help me guys. thanks you in advance.

Oops, try again. trip_cost should take exactly 2 arguments!

my command is as below:

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

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


#10

Hello,

Please if you look through the thread in much detail, you have not done all recommended.

Remove this line:

Also, spending_money on this line should be left without an argument or bracket.

return rental_car_cost(days) + plane_ride_cost(city) + hotel_cost(days) + spending_money

#11

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