def hotel_cost(nights): return 140 * nights def plane_ride_cost(city): return "Charlotte": 183 return "Tampa": 220 return "Pittsburgh": 222
After I run my code, it doesn't run correctly. Please advise.
Ian Michael Jones
You should use the if and else if statement
fo the first on it wil be a if statement it will be something like that
def plane_ride_cost(city): if city == "Charlotte": # if the city is "Charlotte" return 183 # return 183 ...
you are just trying to straight up return all of those values, even though it makes sense, you can't do it like this.
try and set it up like this:
def hotel_cost(nights): return 140 * nights def plane_ride_cost(city): if # this city: return # this value elif # this city: return # this value elif # this city: return # this value elif # this city: return # this value
After trying your suggestion, my code ran correctly. Thanks for all of your help nickgrimes50! I really do appreciate it!
Ian Michael Jones
I did that but it tells me something else
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
what do you mean it tells you something else?
very unlikely @keyboardeot is going to read this topic after 10 months, he is also hijacking the topic.
Charlotte is a undefined variable in his code, it should be a string.
you’re probably right lol, I came across codecademy again after this long hiatus and I saw in my notifications. 1 yr 10 moths is a little delayed
and that makes sense I remember now that we didn’t have any assignments in these lessons.
that is why
"Charlotte" should be a string, otherwise you have a undefined variable. But its very unlikely any one comes back to a topic after 10 months, if you have other unanswered notifications please leave it that way