Pull It Together


#1

'def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
if city == "Charlote":
return 183
elif city == "Tampa":
return 220
elif city == "Pittsburgh":
return 222
elif city == "Los Angeles":
return 475
def rental_car_cost(days):
price = 40 * days
if days >=7:
price = price-50
elif days >=3:
price = price-20
else:
price = 40*days
return price
def trip_cost (days,city):
return rental_car_cost(days)+hotel_cost(days)+plane_ride_cost(city)

could anyone pls tell me what is wrong with this code? I am getting the following message trying to run it "plane_ride_cost('Charlotte') returned None instead of the correct value 183"

thanks

sg


#2

You have a little typo here, I think :slightly_smiling:

Try "Charlotte" with 2 "t" instead of 1. This should fix it :smiley:


#3

Hi frozentofu

Thanks for pointing that out, I actually saw it and fixed it but now it is giving a new error message: " Make sure to define a function named trip_cost."..

the relevant part of the code is
def trip_cost(city,days):
return (rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city))


#4

try to change the places of city and days:

def trip_cost(days,city):


#5

Hi frozentofu,

Thank you for your reply. It worked after resetting the code. I replied earlier from mail mail id but that did not reach you.

Thanks again

sg


#6

You're welcome ^^
Glad if I could help


#7

It worked for me, but I don't understand why.. Could you explain?


#8

Well it's about the order of arguments in the function. Because you define the days argument first and the city argument after, you have to use them in the same order.

Think of it like you defined a recipe (the function) with some ingredients (the arguments), so if you're cooking, you want to use the ingredients in the order from top to bottom (from the left to the right), so you don't miss any of them while cooking.

And the same way works Python in this case, which kind of helps you too so you don't miss out any of the arguments.

Use the arguments the same way you defined them in the function and should work out fine :smiley:

I hope the cooking example didn't confuse you (I just love to cook, that's why this example came in my mind :stuck_out_tongue: )