FAQ: Taking a Vacation - Pull it Together

This community-built FAQ covers the "Pull it Together " 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 _Pull it Together _

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!

Hi all,

I’m about to do this exercise but I just have a couple of issues with the example: Why are the parameters (arguments) different for the third to the first and second? And what does 'returns the sum of the previous two functions when called with a and b, respectively.

Many thanks
Josh

2 Likes

Whenever I press run, an error message pops up saying “trip_cost(‘Charlotte’, 3) returned ‘563’ instead of the correct value 563” or different values. It always says it returns x instead of x, and even though it’s always correct, it never says it is. What did I do wrong?

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

There is no spending_money value in your code.

This worked for me:

#hotel cost function
def hotel_cost(nights):
  #cost is fixed at $140
  return 140 * nights

#plane cost function
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 "There are no flights from that city."

#rental car cost funciton
def rental_car_cost(days):
  cost = 40 * days
  if days >= 7:
    cost += - 50
  elif (days >= 3) and (days < 7):
    cost += - 20
  return cost

#put it all together
def trip_cost(city, days):
  return hotel_cost(days - 1) + plane_ride_cost(city) + rental_car_cost(days)

This is also what I am wondering.

def hotel_cost(night) :
return 140 * night

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 = cost - 50
return cost
elif days >= 3 and days < 7:
cost = cost - 20
return cost

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

So that when you put the amount of days as a parameter, it will automatically plug it into both the rental_car_cost and hotel_cost functions. So there are two parameters and three functions because one of the parameters (days) works for two of the functions.

Majority of code removed. Checker appears to assume no error checking and rejects code as a result. Reference the delta between hotel_cost and hotel_cost_bad functions and with 0 days the trip_cost would return 80 vs 220. Hotel pays you for not staying there.

print “Start”
def hotel_cost(nights):
if (type(nights) == int) or (type(nights) == float):
if int(nights) >=0 :
return 140*int(nights)
else: #int(nights) <= 0:
return 0
else:
print “arg needs to be int or float”
return False

def hotel_cost_bad(nights):
if (type(nights) == int) or (type(nights) == float):
if int(nights) >=0 :
return 140int(nights)
else: #int(nights) <= 0:
print “Allow hotel to pay you for not staying there!”
return 140
int(nights) #0
else:
print “arg needs to be int or float”
return False

print “test hotel”
print hotel_cost(1)
print hotel_cost(0)

def plane_ride_cost(city):

print (type(city) == str)

print city.lower()


elif city.lower() == “tampa”:
return 220

#print “debug”
#plane_ride_cost(“Charlotte”)

def rental_car_cost (days):

print “cost_analysis definition function same function as trip_cost, but cost analysis function has some error checking”
def cost_analysis (city, days):
trip_sum = rental_car_cost(days)
trip_sum += hotel_cost(days -1)
trip_sum += plane_ride_cost(city)
print “trip_sum %s to %s for %s days” %(trip_sum, city, days)
return trip_sum

def trip_cost (city, days):
trip_sum = rental_car_cost(days)
trip_sum += hotel_cost_bad(days -1)
trip_sum += plane_ride_cost(city)
print “trip_sum %s to %s for %s days” %(trip_sum, city, days)
return trip_sum

print “Sample error checking start…”
print “…Example 1…”
print “cost_analysis function call”
sum1 = cost_analysis(“los angeles”, 5.6)
print “trip_cost function call”
sum2 = trip_cost(“los angeles”, 5.6)
evaluation = sum1 == sum2
print “Result funtions return same value %s” %(evaluation)
print “…Example 2…”
sum1 = cost_analysis(“tampa”, 0)
sum2 = trip_cost(“tampa”, 0)
evaluation = sum1 == sum2
print “Result funtions return same value %s” %(evaluation)
print “Sample error checking end…”

Hi - I got 2 questions:

  1. Why do we need to specify parameters for the function of adding the total of all three costs if these parameters are already included in each cost category - isn’t this complicating matters beyond what is needed? A simple addition of three totals shouldn’t need further parameters, no?

  2. How does Python know we are referring to days-1 if the initial function was defined with “nights” as the parameter? Nowhere was this change put into the system?

Thanks for your help

literally same. i checked my code against the example & answer and i see zero differences

1 Like

I’ve had the same issues on a number of exercises. But if I hit “View Solution”, erase their code, then paste mine, it accepts my code.

Same here. But when I put my code, it said define trip_cost when I had already done so. THE CODE IN THE SOLUTION WAS LITERALLY THE SAME!

My code keeps running and running with no end on sight.
I can’t find any errors.

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

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

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

print trip_cost(“Tampa”, 2)