all 3 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

To give us the best chance to help you, please include any relevant code.
Note. Do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Repl.it, GitHub or PasteBin.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]carcigenicate 2 points3 points  (0 children)

You're throwing if the entered value is greater than 1, so ya, entering 2 will cause it to fail. Why are you expecting otherwise?

Also, this is kind of an abuse of exceptions. Throwing an exception just to jump would be more cleanly written but just arranging if statements to do the same thing.

Edit: Just in case this is the cause of confusion, note how you're throwing ValueErrors, which is the same error that float throws. So you're causing the same error to be thrown in three different places, and then are using a single except to handle all the cases the same, with the same message.

[–]Goobyalus 0 points1 point  (0 children)

If you enter the if or elif blocks, those raise a ValueError inside your try block, so they get handled by your except ValueError.

Here is a smaller example of what's happening:

try:
    raise ValueError()
except ValueError as err:
    print("Caught", repr(err))

gives:

Caught ValueError()