Getting there 3/7 - error


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”

I’m getting the following error message with the above code: It looks like plane_ride_cost does not return 183 when the city is Charlotte.


Can someone offer some insight on why it won’t return 183? My code seems to be identical to the example in the lesson, I can’t figure out what I’m doing wrong. The error message isn’t giving me a lot of clues :thinking:


What is the data type of the returned value?


The data type is an integer (miles). I think I found my error, but I want to make sure my reasoning is correct. I needed to define “183” as a string, like this:


Was that the problem with my previous attempt?


why would you want strings? lets see i go three days to Charlotte:

print hotel_cost(3) + plane_ride_cost("Charlotte")

this will give an error.


Ok, I think I’ve solved the issue. I want “Charlotte” to return int(183) not str(183). This seems to work when I run the code now:




If you are converting to int, what are you converting from?


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