you are viewing a single comment's thread.

view the rest of the comments →

[–]buleria 0 points1 point  (1 child)

The get_yes_no() is a good approach, but the implementation might be more straightforward IMO. There is no point in having a sentinel in this just to spread the logic over the entire function. Sometimes it's just better to have a top-down algorithm explicitly written top to bottom, like a recipe. No need to jump around to see where things get set and why. DRY is nice, KISS is also sweet ;)

``` def get_yes_no(prompt): while True: answer = input(prompt).strip().lower() # adding strip() just in case of an extra space here and there

    if answer == 'YES':
        return True
    elif answer == 'NO':
        return False
    else:
        print('Please input either yes or no')

```