2020-09-15 11:49:55 +02:00
|
|
|
def boolInput(question, error='Skriv in J eller N\n', yesNoLetters=('j', 'n')):
|
|
|
|
"""
|
|
|
|
Asks the user a yes/no question and returns a bool based on the input.
|
|
|
|
|
|
|
|
Parameters: \\
|
|
|
|
prompt (str): The prompt asking the user for input \\
|
|
|
|
error? (str): The message to be printed on parsing error \\
|
2020-09-16 15:01:12 +02:00
|
|
|
yesNoLetters? ((str,str)): The letters to be used for representing yes and no in lower caps
|
2020-09-15 11:49:55 +02:00
|
|
|
"""
|
|
|
|
yesLetters = [yesNoLetters[0], yesNoLetters[0].capitalize()]
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
choice = input(question)
|
2020-10-07 13:13:12 +02:00
|
|
|
assert validateInput(choice, yesNoLetters)
|
2020-09-15 11:49:55 +02:00
|
|
|
return choice in yesLetters
|
2020-10-07 13:13:12 +02:00
|
|
|
except:
|
|
|
|
print(error)
|
|
|
|
|
|
|
|
|
|
|
|
def validateInput(input, yesNoLetters):
|
|
|
|
yesLetters = [yesNoLetters[0], yesNoLetters[0].capitalize()]
|
|
|
|
noLetters = [yesNoLetters[1], yesNoLetters[1].capitalize()]
|
|
|
|
|
|
|
|
try:
|
|
|
|
assert input in yesLetters + noLetters
|
|
|
|
return True
|
|
|
|
except:
|
|
|
|
return False
|