Python Python Basics (2015) Letter Game App Exiting

Didier Borel
Didier Borel
2,837 Points

define start movie function

can someone tell me why this doesn't work, It seems pretty straightforward to me

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

5 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 82,446 Points

Hi there,

Let me post you the code that I'm using to pass the code challenge (which is one of many solutions to the problem) and then I'll walk you through it.

Now, it's a bit picky because I can't see any reason in code why you should have a problem defining a function but the code challenge doesn't seem to want it, and to be fair the instructions don't ask for one.

Here I've added some python code using forum markdown. Check out the forum markdown course here on Treehouse to learn how to use it. :)

import sys

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

So you import the library as before and then you define a variable (I'm going to call it response), which will store the input method.

Then you define your condition statement to handle the correct response. Notice that for this code challenge I actually used the lower method, which will help you get the right "no" response no matter if the user is using an upper or lowercase. So you'll either quit the program or print the correct response based on what the user types.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 82,446 Points

The first thing I'd think about changing is storing your input in a variable, and using that variable in your condition.

Also the string you're using needs to match the one suggested in the instructions to pass the code challenge! :-)

Didier Borel
Didier Borel
2,837 Points

thanks Jonathan,. I have tried these corrections, but i still get an error message. I don't see why. import sys def start_movie(var): var=input("Do you want to start the movie? Y/N") if input!="N" or "n": print("Enjoy the show!") else: sys.exit()

Didier Borel
Didier Borel
2,837 Points

thxs for your help. so you are not not defining a function like I did : def start_movie(var): why not ? also you defined a variable called response. Ok , I get that. and you immediately took the lower case, with .lower(). Ok I get that. But you never defined var. and you are saying if var!="n":
so I don't understand why python will give you a correct answer, as you never defined var.

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

so I still don't see why it doesn't work

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 82,446 Points

var was an oversight on my part. I've edited the code in my answer to reflect the correct code. :)

As to the code challenge engine, I can only assume the code challenge simply isn't looking for a function so it won't pass it. But it's not uncommon for a code challenge to reject perfectly valid code in practice when it's simply not the code it is looking for. Computers are very unforgiving like that /