Skip to content

Instantly share code, notes, and snippets.

@gurunars
Created May 4, 2016 13:43
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gurunars/4470c97c916e7b3c4731469c69671d06 to your computer and use it in GitHub Desktop.
Save gurunars/4470c97c916e7b3c4731469c69671d06 to your computer and use it in GitHub Desktop.
Ask for confirmation in Python
def confirm():
"""
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 = raw_input("OK to push to continue [Y/N]? ").lower()
return answer == "y"
@dainiax
Copy link

dainiax commented Jun 18, 2020

For python3 use input()

@cemkaplan75
Copy link

It still perfectly works. Thank you !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment