Python Python Basics (2015) Letter Game App Exiting

Andrew Morgan
Andrew Morgan
577 Points

Didn't get an exit from 'start_movie'

I'm not sure why this isn't getting an exit on the firedoor.py challenge. I originally tried this:

import sys

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

Which failed.

In the end, I solved by adding parentheses after sys.exit, like so:

import sys

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

But in the hangman exercise we just completed before this, Kenneth had used the following:

def welcome():
    start = input("Press ENTER to start or Q to quit: ").lower()
    if start == 'q':
        print("Bye!")
        sys.exit
    else:
        return True

Why is his use of 'sys.exit' working without the parentheses and mine wasn't? Not sure I'm 100% grasping that concept.

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 56,393 Points

Not sure where you are seeing Kenneth use sys.exit() without parens. In the video Letter Game Refinement he uses parens at 9:05 and 10:50

Where are you seeing the use without parens?