Transportation


#1

Not sure what the issue is, any help would be awesome!
I am getting the error: Oops, try again. An error was raised for rental_car_cost(1): global name ‘day’ is not defined

def rental_car_cost(days):
    
    if days >= 7:
        cost -= 50
    elif day >= 3:
        cost -= 20
    else:
        cost = days40
    return cost
    print cost



#2

here:

elif day >= 3:

day isn’t defined anywhere

here:

cost -= 50

cost is not defined

you should first declare cost, then subtract the discount, then return the cost


#3

I tried to do that:
def rental_car_cost(days):
def days(40)
def cost(days * 40)
if days >= 7:
cost -= 50
elif day >= 3:
cost -= 20
else:
cost = days40
return cost
print cost

It says: invalid syntax


#4

this:

def cost(days * 40)

is how you declare a function, not a variable. Why would you use a function here?

not sure what def days(40) is suppose to do.


#5

Well, I am still learning I guess!
I think I did what I am supposed to do:

But the error now is: File “python”, line 22
return cost
^
IndentationError: unindent does not match any outer indentation level

def rental_car_cost(days):
cost = 40 * days
days = 3

if days >= 7:
cost -= 50
elif day >= 3:
cost -= 20
else:
cost = days40
return cost
print cost


#6

here:

days = 3

why would you overwrite the function parameter?

You supply an argument for the parameter at function call, overwriting the function parameter isn’t logic

why did you move the if/elif logic to outside your loop? Please think about the things you do, don’t just randomly try them.


#7

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