I keep getting Oops, try again. Did you create a function called rental_car_cost?


#1

I keep getting
Oops, try again. Did you create a function called rental_car_cost?

But my code looks fine too me.

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
def rental_car_cost(days):
if days >= 7:
return (cost-50)

    elif days >= 3 :
        return (cost-20)

#2

Hey,
I think you're code is not good because you didn't specified the variable ''cost''. Before def rental_car_ cost(days), you need to add cost=40*days.
Take a look to my code :

def hotel_cost(nights):
cost_hotel= nights*140
return cost_hotel

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

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


#3

Where do you get the 40 from?


#4

rent is $40 each day


#5

I am still getting same problem despite assigning a variable to cost

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

#6

That's because you never return the cost if it does not pass one of your if statements

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

It should work like that.


#7

I got the same error.

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

Error

Did you create a function called rental_car_cost?


#8

I did mine differently so just compare, this works for 6/7

city_prices = {
    "Charlotte": 183,
    "Pittsburgh": 222,
    "Tampa": 220,
    "Los Angeles": 475
}

def hotel_cost(nights):
    return 140 * nights

def plane_ride_cost(city):
    return city_prices[city]

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

def trip_cost(city, days, spending_money):
    return hotel_cost(days) + rental_car_cost(days) + plane_ride_cost(city) + spending_money

#9

Both ways work it was a indentation error it was not telling me about. My def
was one space off I guess that messes up the code.


#10

Yes, indentation will mess the code up, google Python Scope. If you do not indent properly then things will be out of scope invalidating code quickly.