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

FHATUWANI Dondry MUVHANGO
FHATUWANI Dondry MUVHANGO
17,796 Points

i have an sys.exit proble

when i run it, it say "didnt get an exit from 'start_movie'." what am i doing wrong?

firedoor.py
import sys

user = input("do you want to start the movie?")
if user != "n" or "N":
    print ("Enjoy the show")
else:
    sys.exit()
Sebastian Sõeruer
Sebastian Sõeruer
12,353 Points

First-

if user != "n" or "N":

better code

if user.lower() != "n":

2 Answers

Hi there,

You need to do the full comparison, rather than just put a comparator in between the two options. Also, it should be an and comparator due to the negated equality test.

import sys

user = input("do you want to start the movie?")
if user != "n" and user != "N":  // two comparisons
    print("Enjoy the show!")
else:
    sys.exit()

If you want to use or for whatever reason, negate the comparison separately:

import sys

user = input("do you want to start the movie?")
if not(user == "n" or user == "N"): // negate the or comparison
    print("Enjoy the show!")
else:
    sys.exit()

But, let's face it, doing as Sebastian suggested and dropping the input to lowercase makes much more sense:

import sys

user = input("do you want to start the movie?")
if user.lower() != "n":
    print("Enjoy the show!")
else:
    sys.exit()

I hope that helps.

Steve.

Glad it helped. :+1: :smile: