18 lines
705 B
Python
18 lines
705 B
Python
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 \\
|
|
yesNoLetters? ((str,str)): The letters to be used for representing yes and no in lower caps
|
|
"""
|
|
yesLetters = [yesNoLetters[0], yesNoLetters[0].capitalize()]
|
|
noLetters = [yesNoLetters[1], yesNoLetters[1].capitalize()]
|
|
while True:
|
|
try:
|
|
choice = input(question)
|
|
assert choice in yesLetters + noLetters
|
|
return choice in yesLetters
|
|
except AssertionError:
|
|
print(error) |