FAQ: Taking a Vacation - Plan Your Trip!

This community-built FAQ covers the “Plan Your Trip!” exercise from the lesson “Taking a Vacation”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Python

FAQs on the exercise Plan Your Trip!

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

This exercise is adding spending for a trip - First function is:

def hotel_cost(nights):
return 140 * nights

Then 2 more functions:

plane_ride_cost(city):
[…]

def rental_car_cost(days):
[…]

At the end we create a function to sum up all our costs:

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

What I don’t understand is how we can change the first function parameter from (nights) to (days - 1) and it still understands how to do the calculation 140 * nights? If anyone could help would be appreciated.

Cheers,

Hi Brooksey,

I just had a problem getting through this part. It looks like in the end it requires the “-1” be dropped off of the hotel_cost function call in trip_cost.

In other words, even though prior parts of the module tell you to code:
def trip_cost(city, days, spending_money):
return rental_car_cost(days) + hotel_cost(days -1) + plane_ride(city) + spending_money

It actually wants this:
def trip_cost(city, days, spending_money):
return rental_car_cost(days) + hotel_cost(days) + plane_ride(city) + spending_money

It looks like there might be an error in the practice module here. Either that or I missed something along the way. Feel free to correct me if I got something wrong as I’m still new to this.

3 Likes

Here’s what I have:

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

print rental_car_cost(5) + hotel_cost(5 - 1) + plane_ride_cost(“Los Angeles”) + 600

I get “1815”, but it keeps spinning and I cannot get to the next exercise.

1 Like

Hi Everyone,

Im not sure if you guys got through this already. I don’t really want to type up the correct answer but I can give you a hint. Just check the instructions again, the answer is in the very first sentence. It gives you the whole line of script how to do it.

" After your previous code, print out the trip_cost( to "Los Angeles" for 5 days with an extra 600 dollars of spending money. "

print something(“city”,days,spending_money)

Sometimes you need to refresh it. If refreshing it does not work, copy your code. then reload browser and paste code. Should work then. This happens to me sometimes when I’m doing something else and the codecademy times out…

1 Like

Hi there, I’d like to ask a question on how indentations affect our outcome.

def trip_cost(city, days, spending_money):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money
print trip_cost(“Los Angeles”, 5, 600)

The code above will not print anything at all. Even though the before statements are valid and true, why does being under a definition cancel out its ability to be printed out?

Can you repost your code, formatted? You can see this post for formatting instructions. Indentation is important in Python and we need to be able to see your indentation to figure out what went wrong (there are several things that could have happened, each based on different indentations).

Based on what you’ve posted thus far, the problem might be that your print statement comes after your return statement. Remember that immediately after a return statement is executed, the function is exited, meaning no more code inside of it will run. Therefore, if print comes after return, that print statement will not run. This all occurs because print is indented to be inside the function trip_cost.

Thought the same as you! Can codecademy correct it so people won’t get confused and frustrated !