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 trialAlex Rodriguez
Front End Web Development Techdegree Student 20,810 PointsDin't get an exit?
Here is my code:
import sys
start_movie = input("Start movie? ")
if start_movie != "n" or start_movie != "N": print("Enjoy the show!") else: sys.exit()
The code challenge keeps telling me that start_movie didn't exit but I thought that is what sys.exit() is for? Am I missing something?
Thank you
2 Answers
Nathan Tallack
22,160 PointsThis is all about the OR evaluation.
Read your code. You are saying:
not n OR not N
Now remember how an OR works. The second it matches one it does not even check for the other. So if I had 4 OR statements in a row if it matches the first one it won't even check for the other three.
So, if an "N" is input, it will never be true because the != 'n' will evaluate as true. Understand.
Try doing it another way. Consider my code below:
import sys
start_movie = input("Start movie? ")
if start_movie == "n" or start_movie == "N":
sys.exit()
else:
print("Enjoy the show!")
If it is n OR if it is N then exit, otherwise print. n or N would be true, everything else would be false.
I think they made this challenge just so we can all make the same mistake you (and I for that matter) did when we encounter it. Tough way to teach us, but effective. ;)
Alex Rodriguez
Front End Web Development Techdegree Student 20,810 PointsGot it, thank you for taking the time to help me.