Python ask yesno
6 Python code examples are found related to "
ask yesno".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: helpers.py From airflow with Apache License 2.0 | 12 votes |
def ask_yesno(question): """ Helper to get yes / no answer from user. """ yes = {'yes', 'y'} no = {'no', 'n'} # pylint: disable=invalid-name done = False print(question) while not done: choice = input().lower() if choice in yes: return True elif choice in no: return False else: print("Please respond by yes or no.")
Example 2
Source File: RvAskInput.py From MNIST-Deep-Learning with GNU General Public License v3.0 | 6 votes |
def Ask_YesNo(sQuestion, default="y"): sInput = input("{}(Now={}) (y/n): ".format(sQuestion, default)) try: if ""==sInput: return "y"==default.lower() or "yes"==default.lower() elif "y"==sInput.lower() or "yes"==sInput.lower(): return True else: return False except ValueError: return False
Example 3
Source File: util.py From rl-benchmark with Apache License 2.0 | 6 votes |
def ask_yesno(label, default="yes"): valid = {"yes": True, "y": True, "Y": True, "no": False, "n": False, "N": False} if default is None: prompt = " [y/n] " elif default == "yes": prompt = " [Y/n] " elif default == "no": prompt = " [y/N] " else: raise ValueError("invalid default answer: '%s'" % default) while True: sys.stdout.write(label + prompt) choice = raw_input().lower() if default is not None and choice == '': return valid[default] elif choice in valid: return valid[choice] else: sys.stdout.write("Invalid input\n")
Example 4
Source File: blackjack1.py From cs101 with GNU General Public License v3.0 | 6 votes |
def ask_yesno(prompt): """ Display the text prompt and let's the user enter a string. If the user enters "y", the function returns "True", and if the user enters "n", the function returns "False" If the user enters anything else, the function prints "I beg your pardon!", and asks again, repeating this until the user has entered a correct string. """ while True : user_input = raw_input(prompt) if user_input == "y" : return True elif user_input == "n" : return False else : print "I beg your pardon!"
Example 5
Source File: qprompt.py From Qprompt with MIT License | 5 votes |
def ask_yesno(msg="Proceed?", dft=None, **kwargs): """Prompts the user for a yes or no answer. Returns True for yes, False for no.""" yes = ["y", "yes", "Y", "YES"] no = ["n", "no", "N", "NO"] if dft != None: dft = yes[0] if (dft in yes or dft == True) else no[0] return ask(msg, dft=dft, vld=yes+no) in yes
Example 6
Source File: interactive.py From wiki-scripts with GNU General Public License v3.0 | 5 votes |
def ask_yesno(question): ans = "" while True: ans = input(question + " [y/n] ") if ans == "y": return True elif ans == "n": return False