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

code gets a bummer...[RESOLVED]

Not sure why on the bummer...there doesn't seem to be any "preview" button for challenges in this course.

import sys

while True:
  try:
   # I put .lower() up here so I didn't have to call it multiple times
    replay = input('Start movie?').lower()
    if replay in ("no", "n"):
      raise sys.exit
    else:
      print("Enjoy the show!")
  # handle the EOF errors I was getting..
  except (EOFError):
      break

After some research found this thread:

https://teamtreehouse.com/community/improvements-to-my-solution-of-the-python-basics-challenge

Somewhat similar code, but not really helpful in nailing down the answer for this challenge..

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You're very close on this challenge. Modified your raise sys.exit line to not raise as an exception and added missing parens to call the exit() function:

import sys

while True:
  try:
   # I put .lower() up here so I didn't have to call it multiple times
    replay = input('Start movie?').lower()
    if replay in ("no", "n"):
      sys.exit()  # <-- Updated
    else:
      print("Enjoy the show!")
  # handle the EOF errors I was getting..
  except (EOFError):
      break

For comparison, my basic solution was not nearly as robust as yours and didn't have exception handling:

import sys

play = input("Start the movie? Y/n ").lower()
if play != "n":
    print("Enjoy the show!")
else:
    sys.exit()