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 () 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 () below!
Agree with a comment or answer? Like () to up-vote the contribution!
The code below is what I inputted for the solution to this module and it kept getting the error message: “trip_cost(‘Tampa’, 5, 0) returned 1100 instead of the correct value 960”
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
However, when checking the solution, it displays this as the answer:
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
Same problem. I copied the solution you posted and paste it in the editor. It still thinks the code is wrong and i’m only able to progress when viewing the solution…
then please post your code here, then we can analyze if something is wrong with your code, or determine if there might be a bug in the exercise validation (small change, but not impossible)
960 is 140 less than 1100, which makes sense because you are only charged for the nights you stay at a hotel. (Mornings are full of sad, tired, hungover people trying not to look each other in the eye).
I’m pretty sure, the argument for hotels should be (days-1).
When writing the code I put an additional conditional on the night stays and rental costs. The conditional was such that if days are 0 you do not get charged for the hotel or rental. The code errors out on the function of 0 days such that you would be given -$140 for staying -1 days at the hotel. I believe the codeacademy evaluating function has a bug.
“trip_cost(‘Tampa’, 0) returned 220 instead of the correct value 80”
In reality this should be either $0 for the cost or $220 depending on how you see it. If days are 0 then you either didnt fly or you flew there and didnt stay or drive around. You would not get a negative value from the hotel.
I typed the correct code and even then the compiler errors pop as have you declared the function ,after clicking the solution the same of what I typed was there .What is this behaviour codecademy?
Why does the test code keep using zero days as an input? And why should the code take a zero days input to mean that the hotel pays you not to stay there? Not a very pretty code, IMO.
Why is spending_money just tacked on in the trip_cost argument without ever being defined? If the code is run, how would it quantify “spending_money” without having an argument associated with it like “days” or “city”?
I completely agree with this statement. All lessons up until now have led me to believe arguments must be defined yet this is accepted? Unless I am missing something easy, I am confused as to why this code works.