Got an error - Activity 4: Transportation


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

https://www.codecademy.com/courses/learn-python/lessons/taking-a-vacation/exercises/transportation-?action=lesson_resume&link_content_target=interstitial_lesson

<In what way does your code behave incorrectly? Include ALL error messages.>
I got an error message with “Did you create a function called rental_car_cost?”

<What do you expect to happen instead?>
I believe my code should be working just fine. If not, please correct.

```python

def rental_car_cost(days):
cost = 40 * days
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
else:
return cost

<do not remove the three backticks above>

#2

To show the indentation of your code you need to format your code properly.

right now i can say your function doesn’t return anything for days above 6 or 2.


#3

Hi rcodeman,

Thanks for a reply. I have tried to work around it including indentation but found out it can be fixed by simply refreshing a browser! so I guess it may have some bugs.


#4

Did you pass without returning the correct amount for days 7 or 3 ?

can i see your updated code?


#5

Yes, it passed without fixing anything. so here’s a full 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 = 40 * days
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
else:
return cost


#6

Yes, the same happens to me a lot. Even the code is the same with the answer it gives error.


#7

I think it turns out to be a bug issue. If it happens again, try to refresh your web browser otherwise clear your cache. It might help.


#8

Then it must be a bug.because you have to return the correct amount if your conditions are true.
right now it doesn’t return anything if the conditions are true.


#9

Just FYI, I’ve managed to make a code right, see below:

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

Even though, it allowed me to go through the next chapter without correction. Kinda weird but true.

So for anyone who has the same issue like me, try to compile it with an external compiler for cross-checking.


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.