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 trialFHATUWANI Dondry MUVHANGO
17,796 Pointsi have an sys.exit proble
when i run it, it say "didnt get an exit from 'start_movie'." what am i doing wrong?
import sys
user = input("do you want to start the movie?")
if user != "n" or "N":
print ("Enjoy the show")
else:
sys.exit()
2 Answers
Steve Hunter
57,712 PointsHi 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.
FHATUWANI Dondry MUVHANGO
17,796 Pointsyeah did help. thank you guys
Steve Hunter
57,712 PointsGlad it helped.
Sebastian Sõeruer
12,353 PointsSebastian Sõeruer
12,353 PointsFirst-
if user != "n" or "N":
better code
if user.lower() != "n":