Split input functions for custom implementations
This commit is contained in:
parent
d9c5d7d400
commit
72478e8199
|
@ -8,11 +8,21 @@ def boolInput(question, error='Skriv in J eller N\n', yesNoLetters=('j', 'n')):
|
|||
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
|
||||
assert validateInput(choice, yesNoLetters)
|
||||
return choice in yesLetters
|
||||
except AssertionError:
|
||||
print(error)
|
||||
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
|
|
@ -14,6 +14,14 @@ def inputTypeCheck(
|
|||
while True:
|
||||
inputValue = input(prompt)
|
||||
try:
|
||||
assert validateInput(inputValue, type)
|
||||
return type(inputValue)
|
||||
except ValueError:
|
||||
print(error)
|
||||
except AssertionError:
|
||||
print(error)
|
||||
|
||||
def validateInput(input, type):
|
||||
try:
|
||||
_ = type(input)
|
||||
return True
|
||||
except:
|
||||
return False
|
Loading…
Reference in New Issue