Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Letter Game App Exiting

Alex DiFazio
Alex DiFazio
579 Points

sys.exit code not working?

Can anyone give me a tip on why this code isn't working? From the guidelines, I feel like I am giving exactly what is needed. What am I missing?

firedoor.py
import sys


def start_movie():
    input('Do you want to start the movie? Y/n').lower()
    if input == 'n':
        sys.exit()
    else:
        print("Enjoy the show!")

1 Answer

Hey Alex! Your close, but you have a couple of issues. One is that you dont need to define this as a function, just write the code. Secondly is that an input will return the value that it recived, so you cant say:

input("Input something")
if input == "whatever"

Input is never the same as something, instead you should store the returned value from input in a variable, and then check if that variable is the same as "whatever". So your final code should look something like:

import sys

returned_value = input('Do you want to start the movie? Y/n').lower() #Added a variable for whatever input returns
if returned_value == 'n':
    sys.exit()
else:
    print("Enjoy the show!")

Hope this helps!