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

huyen nguyen
huyen nguyen
850 Points

what's wrong

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

firedoor.py
import sys
x= input('Do you want to start the movie? ')
if x=="n" or "N":
    sys.exit()
else:
    print ('Enjoy the show!' )

2 Answers

andren
andren
28,558 Points

When you use OR to combine conditions you need to have a complete condition on both sides, in other words you need to compare x to a letter on both sides of the OR like this:

x == "n" or x == "N"

You can't just give a list of letters to compare to, the condition has to be something that would work even if it was used on its own without the OR.

It's also worth mentioning that instead of manually checking if it is "n" or "N" you could just turn x into a lower case string using the lower method. That way you can just compare it to "n" without worrying about what case was actually used in the input. Like this:

import sys
x= input('Do you want to start the movie? ').lower()
if x=="n":
    sys.exit()
else:
    print ('Enjoy the show!' )
huyen nguyen
huyen nguyen
850 Points

Thank so much Andren