Pull It Together 5/7


#1

def hotel_cost(days):
return hotel_cost(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):
cost = days*40
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
return cost
def trip_cost(city, days, nights):

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

Oops, try again. hotel_cost(1) raised an error: maximum recursion depth exceeded


#2

HI first here

def hotel_cost(days):
   return hotel_cost(140*days)

you should call the function hotel_cost() but you should return 140 * days

then here

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

your function trip_cost() should have only two argument city and days so remove nights


#3

But I'm having the same problems occurring when executing the programs
Oops, try again. hotel_cost(1) raised an error: maximum recursion depth exceeded


#4

DId you do what I said? ..if so can you post your code?


#5

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

My question is that how do we call 140 for hotel cost with days?
why is that error always occurring


#6

The error is from here

def hotel_cost(days):
    return hotel_cost(140 *days)

you defiine hotel_cost() then inside the function hotel_cost() you call again hotel_cost() that why you get
Oops, try again. hotel_cost(1) raised an error: maximum recursion depth exceeded
So you should do it like that

def hotel_cost(days):
    return 140 *days

#7

Yes Finally obtained with that. thanks.
But another question is that why in the console windows it shows none


#8

because you didn't call the function trip_cost()


#9

ok Thanks for the help wiz.


#10


why is it asking me define a function which is already defined


#11

HI inside you trip_cost function you should indent the return statement..


#12


#13

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


#14

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

my code is wrong and it keeps saying that there is something wring with plane ride, can you please help me


#15

Hi this partof the code

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

just remove this line

def hotel_cost(days):

#16

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

thanks but its coming up with this error now, do you know what I should remove or add


#17

the line I made you remove

def hotel_cost(days):

shouldn't be inside the function trip_cost() but on top of all your code which should return 140 * days so it be like that

def hotel_cost(days):
   return 140 * days

#18

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):
rent = 40 * days
if days >= 7:
rent = rent - 50
elif days >= 3:
rent = rent - 20
return rent
def hotel_cost(days):
return 140 * days
def trip_cost(city,days):
return rental_car_cost(days) + hotel_cost(days) + plane_ride cost(city)

thanks, now its the last line, line 20 that has an error what am I missing?


#19

can you post the error you get?


#20

sure

Oops, try again. Your code looks a bit off. Feel free to peek back at earlier exercises if you need a refresher! Take a look at the console window for the error message from the interpreter.

that's it there