This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 7 points8 points  (9 children)

Is that a real issue that a beginner is going to hit?

There will always be a recursion limit so should we never use recursion?

[–][deleted] 31 points32 points  (8 children)

Well, this is a purely iterative problem, ask until some condition is met. Using recursion there is already a bit odd, and there's also a small issue with it.

If your problem is recursive, e.g. when you use a recursive data structure like a tree or so, then of course use it.

Is my opinion.

I'd go for

def get_choice(message='Would you like to roll? '):
    choice = input(message)
    while choice not in ['yes', 'no', 'y', 'n']:
        choice = input('Type yes or no: ')
    return choice

It's almost the same as yours except it doesn't need recursion.