Getting there 3/7 - error


#1

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.

21%20AM

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:


#2

What is the data type of the returned value?


#3

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:

plane_ride

Was that the problem with my previous attempt?


#4

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.


#5

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:

Charlotte

Thanks!


#6

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


#7

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