Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

Python Basics / Letter Game / Code Challenge / "Exiting"

so, below code works to pass the challenge.... but it throw NameError: name 'what_was_inputted" is not defined. i am using v2.7.11 does it make any difference with v3.0 in this case?

import sys

movie = input("Do you want to start watching movie? Y/N")
for letter in movie:
    if letter == "n" or letter == "N":
        sys.exit()
    else:
        print("Enjoy the show!")

I don't understand why you are using a for loop when the string holds one letter:

After the line of your movie declaration I would just do:

if movie.lower() == 'n':

4 Answers

OK, this is sorted now,

there is no problem with indentation, basically for python-2.7 ALWAYS use

raw_input

instead of

input

Here try this:

import sys

movie = input("Do you want to start watching movie? Y/N")

if movie.lower()=='n':
  sys.exit()
else:
  print("Enjoy the show!")

your solution not to use "for" loop look better but still not working.

It just needs to be properly indented- I just typed it, I didn't run it.