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 trialMaximilian Hill
Python Development Techdegree Graduate 7,661 PointsGuessing Game: Need help raising value Error
Hello,
I've already submitted the project. Everything works except getting it to raise a value error when the guess is below one or over twenty. I tried adding and raising the exception on line 36 but it keeps giving me a syntax error. Please what do I need to do to get this working?
My code: https://w.trhou.se/kqycimqlu9
Thanks for the help!
1 Answer
Asher Orr
Python Development Techdegree Graduate 9,409 PointsHi Max! You need to indent your if statement on line 36.
When you implement Try Blocks, the if statements (what you're using to Raise ValueErrors) need to be nested within the try block.
Like this:
try:
guess = int(input("Please choose a number between 1 and 20: "))
time.sleep(1)
if guess <= 0 or guess > 20:
raise ValueError("That is not within the given range")
continue
except ValueError as err:
print("Opps, Thats an invalid response. Please try again...")
print(f"({err})")
continue
Maximilian Hill
Python Development Techdegree Graduate 7,661 PointsMaximilian Hill
Python Development Techdegree Graduate 7,661 PointsAsher Orr Thank you!
Asher Orr
Python Development Techdegree Graduate 9,409 PointsAsher Orr
Python Development Techdegree Graduate 9,409 PointsYou're welcome! Be sure to mark "best answer" on that response, so others know you've been helped.