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!

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


Maximilian Hill
Maximilian Hill
Python Development Techdegree Student 4,967 Points

Guessing Game: Need help raising value Error


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
.a{fill-rule:evenodd;}techdegree seal-36
Asher Orr
Python Development Techdegree Graduate 9,252 Points

Hi 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:

                guess = int(input("Please choose a number between 1 and 20: "))

                if guess <= 0 or guess > 20:
                    raise ValueError("That is not within the given range")

            except ValueError as err:
                print("Opps, Thats an invalid response. Please try again...")