NameError: name 'days' is not defined


8.Taking a Vacation, 4.Transportation

File "python", line 15, in
NameError: name 'days' is not defined

Line 15 is if days >= 7:
I have 'days' defined in argument. My code is very similar to the example code as they use the argument 'tickets' and then to use 'tickets' in what would be the equivalent of 'days' in line 15.
I am asking why it is saying 'days' is not defined when I have it in the argument.
Please don't be harsh if i made a very simple mistake.

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


you should put the if/elif and else inside the function:

def example():
   if True:
      print "if nested inside the function"

your if it outside the function causing days to be outside the function as well

You should also return the cost, i don't see you use the return keyword anywhere


Thank you. It solved that problem but now I have gone wrong somewhere else.


you could try to troubleshoot yourself? If you need more help, post an updated version of your code + error message and then i will help you further


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