# "Cost is not defined"

#1

I'm stuck here
nights= raw_input("Nights?")
days= raw_input("Days?")

it gives the error "cost is not defined"

``````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):
cost = days * 40
if days>=7:
cost - 50
elif days>=3:
cost - 20``````

#2

`cost` has a local scope, it only exist inside the function

why are your if and elif not inside the function?

#3

Indentation is how Python knows whether things are nested in a hierarchy. So @stetim94 is pointing out that only `cost = days * 40` is really inside the function `rental_car_cost()`

#4

at this point in the course, i am assume students know this.

#5

"cost has a local scope, it only exist inside the function

why are your if and elif not inside the function?"
So I won't get the error "unexpected indent"

#6

but looking at the design of your function, the if and elif need to be inside the function. Show us the code where you get an indent error

#7

Your if and elif of the function rental_car_cost are not in its scope.
Always write your code with proper indentation.

#8

changed it now it's

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

#9

now you use cost before you define it? The function should `return` the cost of renting a car

#10

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