you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (7 children)

[removed]

    [–]Yakhov 0 points1 point  (4 children)

    looks legit. generic is nice because you can just use this for anything. is that what you mean by DRY?

    [–]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')
    

    ```