Console-calculation correct but there appears an Error-Message in the Editor


Hey there,

I'm just trying to get this Code to be accepted.
The Code works, all Calculations are correct. The only Problem is that in the Editor there comes the Error-Pop Up telling me
"plane_ride_cost('Charlotte') returned False instead of the correct value 183"
This even appears if the Chose was i.e. Tampa.
As I said all the Calculations with all by me tried Combinations are getting calculated and printed accurate in the console, the only Problem is that there is this Pop Up that huffs me a little bit.

I even thought about if the Problem could be that maybe the Site-internal Interpreter didn't expected a code like this, but in earlier Lessons it told, for example, "this lesson is not attended to get inputs" or something like that. In the whole Section till "Taking a Vacation" I worked with Inputs and all the Lessons were able to get completed with the first three functions. So I don't think that it is the amount of the code, but a bug in it I don't see maybe?

That's the Code - Thanks for your Suggestions what could be the Problem!

def hotel_cost(nights):
    hotel_calc = 140*nights
    print "hotel_calc : %d" % hotel_calc
    return hotel_calc
def plane_ride_cost(city):
    if city == 1:
        flight_calc = 183
        print "Destination: Charlotte / Costs: %d" % flight_calc
        return flight_calc
    elif city == 2:
        flight_calc = 220
        print "Destination: Tampa / Costs: %d" % flight_calc
        return flight_calc
    elif city == 3:
        flight_calc = 222
        print "Destination: Pittsburgh / Costs: %d" % flight_calc
        return flight_calc
    elif city == 4:
        flight_calc = 475
        print "Destination: Los Angeles / Costs: %d" % flight_calc
        return flight_calc
        print "MALFUNCTION"
        return False
def rental_car_cost(days):
    car_calc = 40*days
    print "car_calc : %d" % car_calc
    if days >= 7:
        car_calc = car_calc-50
        print "car rental costs : %d" % car_calc
        return car_calc
    elif days >= 3 and days < 7:
        car_calc = car_calc-20
        print "car rental costs : %d" % car_calc
        return car_calc
        print "car rental costs : %d" % car_calc
        return car_calc
def trip_cost(city, days):
    hotel_calc = hotel_cost(int(input("How many Nights You want to stay? ")))
    print "HOTEL_CALC %d" % hotel_calc
    print ""
    print "For Dest. Charlotte press [1] \
    For Dest. Tampa press [2] \
    For Dest. Pittsburgh press [3] \
    For Dest. Los Angeles press [4]"
    print ""
    flight_calc = plane_ride_cost(int(input("Enter your Destination: ")))
    print type(flight_calc)
    print ""
    car_calc = rental_car_cost(int(input("How may Days you want to rent a Car? ")))
    print ""
    trip_summary = int(hotel_calc + flight_calc + car_calc)
    print type(trip_summary)
    print "The calculated Costs are : %d" % trip_summary
    return trip_summary


The issue in your programme is, that you use your own input, instead of using the function as they want you to.

So let me explain you what is actually going on: :triumph:

You call your functions "plane_ride_cost","rental_car_cost","hotel_cost" and want the user to input values for the destination and days and so on. Those will be the values input in the function.

It get checked and gives you the right values. Works all fine, BUT: :disappointed:

The codeacademy editor comes after you and wants to use your programme as well, after you're done with your input, and that's where the issue begins.

The site now wants to input "Charlotte" as city here:

Which is neither 1 nor 2 because_ it's a string and not an integer (number)_ :slightly_smiling:
So because it's none of them, it goes directly to "else", where the output will be False . :frowning:

Let me show you how the site calls your function after you're done:

trip_cost("Charlotte", 3)

The way to pass the exercise, you should just leave out the input and let the values, written when you call the function be used for the calculations and it should work :smiley:


Okay, that makes sense, I will try to solve it in the demanded way. Thanks @frozentofu ! :slightly_smiling:



def plane_ride_cost(city):

if city== "Tampa" or "tampa":
    return 220 
elif city== "Charlotte" or "charlotte":
    return 183
elif city== "Pittsburgh" or "pittsburgh":
    return 222
elif city== "Los Angeles" or "los angeles":
    return 474

what is the mistake in this code?
i am getting the same error?



try to re-think about the " if sth == sth or ..." - condition.
If you don't find it, reply here and I will try to help you figure it out :slightly_smiling:

And (btw) take a look at the Ticket-Price for LA... They didn't gave me any discount :smiley:



@tagninja09663: Whenever we use if or elif we are supposed to compare one thing with another.
The way you did there will always return the number 220 because it will ask:
"Is the value stored in the variable city equal to "Tampa" or "tampa"?

Let's suppose that in city we have "Tokyo" and in that case "Tokyo" isn't equal to "Tampa" but since there's no comparison on the second statement, the commands inside the first if will be executed because it will be like:

if F ''' because "Tokyo" is not equalto "Tampa" ''' or  True '''due to the fact that this statement is not an empty string, it has a value so it's different than zero.''

It will always be true because there's actually something in there, the string, in this case, is not empty.


@g4be so why isnt comparing bit by bit?
and whats the solution for this?


@tagninja09663: That's because you're not telling your program what to use on your second statement so it can be compared.
If you want to check if a string is either "Los Angeles" or "los angeles", you have to compare a value that was stored into a variable and do:

if variableName == "LA" or variableName == "la":
   #Do something


@g4be i am returning the value..isnt that enough?
can you edit the code and write, please?


@tagninja09663: You're supposed to also check if the argument city contains the value "los angeles", you just need to compare it just like you did with "Los Angeles".