You are using the input() function on Python 2. Use raw_input() instead, or switch to Python 3.
input() runs eval() on the input given, so entering n is interpreted as python code, looking for the n variable. You could work around that by entering 'n' (so with quotes) but that is hardly a solution.
In Python 3, raw_input() has been renamed to input(), replacing the version from Python 2 altogether. If your materials (book, course notes, etc.) use input() in a manner that expects n to work, you probably need to switch to using Python 3 instead.