Even copied code from solution doesn't work

Edit: On the next exercise, passing values through the same exact code made it pass all of the tests. I believe there is a bug in this exercise, where the test for the correct number has the wrong value.

It looks like the code I input is the exact same as the solution, but it won’t pass the tests. When I copy and paste the exact solution, it won’t run, but when I click solution and leave it as is, it passes all the tests. Anyone know what’s wrong?

Here is the link: https://www.codecademy.com/courses/learn-python/lessons/taking-a-vacation/exercises/hey-you-never-know?action=resume_content_item

Here is my code:

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

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

LOL

That exercise used to have a number of nights being equal to number of days.
If you ask me, that is perfectly reasonable, there are arrival and departure configurations where this is the case.

But people would sometimes complain that the number of nights should most definitely be one less. I guess someone caved in, or somehow managed to think the same way, because now it is.

However, there are test cases where the number of days stayed are 0, leading to tests with -1 nights at a hotel, and codecademy failed to remove those test cases.

Another thing that looks like it wasn’t updated is the solution, that is now wrong, which is why it doesn’t pass.

Most correct solutions still pass, so long as their hotel cost functions produce -140 for -1 nights. Your solution is probably not correct, the code you posted isn’t.
The mistake is probably coming from codecademy though, providing you with code that wasn’t your own (maybe from resetting or something like that) which wasn’t updated to have 1 less nights than days.

3 Likes