Could somebody explain what im doing wrong Did you create a function called plane_ride_cost?


#1

def hotel_cost(nights):
return 140 * nights

def plane_ride_cost(city): 
        if city == "Charlotte":
           plane = 183
             return (city)

#2

city = raw_input("Where will you be going?") 
def hotel_cost(nights):
    return 140 * nights
  
    
    def plane_ride_cost(city): 
        if city == "Charlotte":
            cost = 183
            return cost
        elif city == "Tampa":
              cost = 220
              return cost
        elif city == "Pittsburgh":
            cost = 222
            return cost
        elif city == "Los Angeles":
            cost = 475
            return cost
        else:
             return "Not a valid destination."

I GOT this somebody any suggestion on what i did wrong?


#3

your plane_ride_cost function is inside your hotel_cost function, the plane ride cost function should be outside/after the hotel_cost function (hint: indention)

also, this:

return "Not a valid destination."

is risky, the code you will build later will expect a integer result from plane ride cost function. Keep this is mind. You can leave the code, but be aware of this problem


#4

oh so the code was good but the (hint: indention) was bad could you maybe explain it a litte more so that i understand how to use it


#5

well, at this point in the course i assume you know how to use indention to determine what is inside/outside a function


#6

Yeah i know what you mean but the problem is. I think i know how to do it. but dont really understand what it do? do you understand that. I like to understand what im doing already looking on the internet but still not sure. Thats why im asking you. Hope that you can help me understand phython


#7

well, you could simply place the plane_ride_cost function outside the hotel_cost function by giving plane ride cost an indention of 0 spaces, anything which has lesser indent then the function is outside the function


#8

city = raw_input("Where will you be going?") 
def hotel_cost(nights):
    return 140 * nights
  
    
def plane_ride_cost(city): 
         if city == "Charlotte":
             cost = 183
             return cost
         elif city == "Tampa":
               cost = 220
               return cost
         elif city == "Pittsburgh":
             cost = 222
             return cost
         elif city == "Los Angeles":
             cost = 475
             return cost

So every function needs zero space's so that python see its a new function it works like that ?


#9

this code work every function start with 0


#10

yes and no, the incorrect code you had first you nested the plane_ride_cost function inside hotel_cost function, which is valid (you can nest functions), but the exercise wants you create a bunch of separate functions, not nested functions

there are two things at play here: valid syntax and design of your program


#11

i understand. if its not hard could you show one thats nested and one that is seperated if its not a problem for you. Than i think i really understand it


#12

No, you don't understand. If you did, you wouldn't ask this. You first had a nested function:

city = raw_input("Where will you be going?") 
def hotel_cost(nights):
    return 140 * nights
  
    
    def plane_ride_cost(city): 
        if city == "Charlotte":
            cost = 183
            return cost
        elif city == "Tampa":
              cost = 220
              return cost
        elif city == "Pittsburgh":
            cost = 222
            return cost
        elif city == "Los Angeles":
            cost = 475
            return cost
        else:
             return "Not a valid destination."

and then you correct it to separate functions:

city = raw_input("Where will you be going?") 
def hotel_cost(nights):
    return 140 * nights
  
    
def plane_ride_cost(city): 
         if city == "Charlotte":
             cost = 183
             return cost
         elif city == "Tampa":
               cost = 220
               return cost
         elif city == "Pittsburgh":
             cost = 222
             return cost
         elif city == "Los Angeles":
             cost = 475
             return cost

#13

I think i got it thanks for youre time men:)

city = raw_input("Where will you be going?")
def hotel_cost(nights):
return 140 * nights

def plane_ride_cost(city):
if city == "Charlotte":
cost = 183
return cost
elif city == "Tampa":
cost = 220
return cost
elif city == "Pittsburgh":
cost = 222
return cost
elif city == "Los Angeles":
cost = 475
return cost

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


#14