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!