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

Exiting

So the error is didn't get an exit from start_movie. When I tried it in the terminal it would only do whichever one I put first so if I put the sys.exit() first it would only exit no matter what I did.

firedoor.py
import sys

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

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I think you're doing really well and you're actually really close here. But first let's talk about a logic error that you have. You're checking for if the start_movie is not equal to n OR the start_movie is not equal to N. Now what this would mean is that if either one of those are true, the "Enjoy the show!" would print out. So if the user enters "n", enjoy the show would print out as the the second condition would become true. So what we're looking for here is an AND operator. If the answer not "n" and the answer is not "N" then print out the message.

Also, there's a problem in your conditional statement. You've left out what you're supposed to be comparing "N" to. And because "N" is a non-zero value it will be "truthy". This results in that expression always being true and the else statement will never be invoked.

This is what your conditional statement should look like:

if start_movie != 'n' and start_movie != 'N':

I'd suggest you take a good look at it and make sure you understand it before moving on. Hope this helps! :sparkles:

Thank you. That makes sense

Although this has already been answered, just thought I'd add an additional way which may help make it a bit more readable perhaps by using a list or by using string manipulation:

# Using a list.
if start_movie not in ['n', 'N']:

# Manipulating the start_movie string by making it always upper case.
if start_movie.upper() != 'N'

Yeah that helps. Thanks!