Skip to content

Instantly share code, notes, and snippets.

@cristian-aldea
Created September 27, 2021 03:14
Show Gist options
  • Save cristian-aldea/d0f5d5c074a200b6d1606f4c94b9e3e8 to your computer and use it in GitHub Desktop.
Save cristian-aldea/d0f5d5c074a200b6d1606f4c94b9e3e8 to your computer and use it in GitHub Desktop.
Python: Confirmation function
def confirm() -> bool:
"""
Ask user to enter Y or N (case-insensitive).
:return: True if the answer is Y.
:rtype: bool
"""
answer = ""
while answer not in ["y", "n"]:
answer = input("Continue? [y/n]? ").lower()
return answer == "y"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment