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 trialAleksandar Kosev
4,603 PointsI know its a stupid and simple mistake but i cant seem to find it!
#Use input() to ask the user if they want to start the movie.
#If they answer anything other than "n" or "N", print "Enjoy the show!". Otherwise, call #sys.exit(). You'll need to import the sys library.
import sys
ans=input("Wana start the movie")
if ans=='n' or ans=='N':
sys.exit()
else:
print("Enjoy the show!")
[MOD: added code markup]
5 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Aleksandar,
I think it was just a glitch in the code checker. Your code is correct, and when I copy/paste it into the challenge, it does pass.
Maybe, just copy the your own code from above, refresh the challenge and paste in the code again.
:)
Steve Hunter
57,712 PointsThis worked:
import sys
ans = input("Want to start the movie? ")
if ans =='n' or ans =='N':
sys.exit()
else:
print("Enjoy the show!")
EDIT: Your code's fine! :-)
Steve.
Jane Chester
5,411 PointsHey!
The only change I have made in the following extract is converting the 'N' to lowercase using the lower() function- this just helps to make the code a little shorter.
import sys
answer = input("Do you want to start the movie?")
if answer.lower() == 'n':
sys.exit()
else:
print("Enjoy the show!")
oz izhak
1,940 Pointsanother option :
answer = input("Do you want to start the movie?").lower()
Thorbjørn Bak Jensen
15,043 Pointswouldn't it be cleaner to write:
if ans.lower == 'n
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsI agree - it failed when I ran it first time round, then works fine now!
Aleksandar Kosev
4,603 PointsAleksandar Kosev
4,603 Pointswell i almost broke the pc staring at it for 30 minxD it worked now. Thank you^^