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

Aleksandar Kosev
Aleksandar Kosev
4,603 Points

I 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
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey 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.

:)

I agree - it failed when I ran it first time round, then works fine now!

Aleksandar Kosev
Aleksandar Kosev
4,603 Points

well i almost broke the pc staring at it for 30 minxD it worked now. Thank you^^

This 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
Jane Chester
5,411 Points

Hey!

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
oz izhak
1,940 Points

another option :

answer = input("Do you want to start the movie?").lower()

Thorbjørn Bak Jensen
Thorbjørn Bak Jensen
15,043 Points

wouldn't it be cleaner to write: if ans.lower == 'n