Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Letter Game App Exiting

stuck in the question

hello, I think i've made my conditions well. Somebody understands where my problem is? thank you :)

firedoor.py
import sys

# ask user to start the movie 
user_choice = input("Do you want to start the movie? Y/n ")

# start the movie if user answer isn't "n" or "N"
def start_movie(user_choice):
    # if user answer isn't "n" or "N" start the movie
    if user_choice != "n" or user_choice != "N":
        print("Enjoy the show!")
    # otherwise exit
    else:
        sys.exit()

2 Answers

Two problems!!! First is you haven't called the function, even though you defined it.

Second is a little problem in the if condition: what you are checking is: if user_choice is 'n' and also user_choice is 'N' ... only then exit.

Little complicated! :) its like negative of negative is positive.

Here is the code... try this and you'll understand better practically.

import sys

# ask user to start the movie 
user_choice = input("Do you want to start the movie? Y/n ")

# start the movie if user answer isn't "n" or "N"
def start_movie(user_choice):
    # if user answer isn't "n" or "N" start the movie------------------>check AND in line below.
    if user_choice != "n" and user_choice != "N":
        print("Enjoy the show!")
    # otherwise exit
    else:
        sys.exit()

start_movie(user_choice)

thanks Krishna, I understand that I haven't called the function, but in the condition I don't understand why should I use "and" instead of "or", because the user can answer "n" or "N"

Tiago Ramos , You are right... user can answer "n" or "N" for "NO" but he can't answer "n" and "N" for "YES".

There are three ways to understand this, first 2 are complicated but the last is easy one and i prefer.

. First... lets see the original condition statement.

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

Now the question says...if choice is not equal to 'No' print something. Perfectly correct score!.

But we have divided this condition into two parts: (choice!='n') , (choice!='N').

Now BOTH of these condition means "YES" but EITHER of these condition not necessarily means "YES". . .

Second...

So if either of the condition(choice=='n' , choice=='N') satisfies it's a "NO".

But that does not means that either of these condition fails means a "YES".

Rather when both these conditions fails then only it means "YES".

lets say:
cond1 => choice=='n'
and 
cond2=> choice=='N'
then
cond1 OR cond2 = NO
lets complement both these sides

complement(cond1 OR cond2) = complement(NO)
complement(cond1) and complement(cond2) = YES
where complement(cond1) = choice!='n'
and complement(cond2) = choice!='N'

Hence,
cond1 and cond2 = YES

All too complicated, right.

Third...

The best way to verify this(i like the most) is through test cases.

According to original code:

choice!='n' OR choice!='N' => YES

Here, lets see if value is : 1)n, 2)N, and 3)L ..... satisfying in the code:

1) 0 + 1==> yes

2) 1 + 0==>Yes

3) 1 + 1 ==> Yes

Lets consider an imaginary case where the value is both 'n' and 'N' at the same time.

0 + 0 ==>No.

I hope this was helpful.

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

user_choice.lower().....it's cleaner and shorter and you DRY. and than you don't need the AND... my opinion...