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 trialalekseibingham
4,491 PointsUse input() to ask the user if they want to start the movie. If they answer anything other than "n" or "N"...
Im attempting to get it to print if they dont answer with an n or N, or quit if they do. I keep getting a syntax error on line 3 and on my own at home projects, when ever i attempt to use something like this to replay a game i made, it never seems to work!
import sys
choice = input("Would you like to start the movie?: ".lower())
if choice != "n" or "N":
print("Enjoy the show!")
else:
sys.exit()
2 Answers
taejooncho
Courses Plus Student 3,923 PointsWhy would you need or != "N"? You put .lower() in the input, so any input is going to be lowercased. Thus your if statement will work fine if you just say
if choice != "n":
alekseibingham
4,491 PointsI still cant seem to figure it out
import sys
answer = input("Start the movie, Y/n?: ".lower())
if answer != "n":
print("Enjoy the show!")
else:
sys.exit()
taejooncho
Courses Plus Student 3,923 PointsOkay, The issue was in line 2. You ended the bracket at the wrong place.
choice = input("Would you like to start the movie?: ".lower())
What this will do is make the entire string "Would you like to start the movie?" all into lower case, but that is not what you want.
You want the input of the person to be lower thus, you write .lower() after the input("Would you like to start the movie?: ").lower()
What you want to write ultimately is these codes.
Try
import sys
choice = input("Would you like to start the movie?: ").lower()
if choice != "n":
print("Enjoy the show!")
else:
sys.exit()
ryan smith
687 Pointstaejooncho why does there need to be a
.lower()
why can't we just have
if answer != "n" or answer != "N":
alekseibingham
4,491 Pointsalekseibingham
4,491 Pointseven if i take out .lower it dose not work
taejooncho
Courses Plus Student 3,923 Pointstaejooncho
Courses Plus Student 3,923 PointsBut the challenge asks you to put lower()
taejooncho
Courses Plus Student 3,923 Pointstaejooncho
Courses Plus Student 3,923 PointsI also want to address the error the python is giving to you. When you look at your line 3, where your if statement happens, That code and below should not be indented, but your codes are indented.
So first I would unindent the code from line 3 and below.
As for the future reference, when you want to write or in an if statement you can't write it like this.
if choice != "n" or "N":
it needs to be