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 trialjames white
78,399 Pointscode 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
Treehouse Moderator 68,441 PointsYou'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()
james white
78,399 PointsThanks Chris,
There are many TeamTreehouse forum threads dealing with this EOF error:
https://teamtreehouse.com/community/i-keep-getting-an-eof-error-on-python
https://teamtreehouse.com/community/-what-is-eoferror-eof
https://teamtreehouse.com/community/eoferror
https://teamtreehouse.com/community/eoferror-for-python-database-add-an-entry
https://teamtreehouse.com/community/eof-error-on-adding-an-entry
https://teamtreehouse.com/community/ctrld-throws-eoferror-on-next-line-containing-input-prompt
...so I'm glad I got a chance to explore the handling for this error.