diff --git a/common/inputChecking/boolInput.py b/common/inputChecking/boolInput.py index 0f18294..fd2e586 100644 --- a/common/inputChecking/boolInput.py +++ b/common/inputChecking/boolInput.py @@ -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) \ No newline at end of file + 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 \ No newline at end of file diff --git a/common/inputChecking/typeCheck.py b/common/inputChecking/typeCheck.py index 534e9dd..a8a349b 100644 --- a/common/inputChecking/typeCheck.py +++ b/common/inputChecking/typeCheck.py @@ -14,6 +14,14 @@ def inputTypeCheck( while True: inputValue = input(prompt) try: + assert validateInput(inputValue, type) return type(inputValue) - except ValueError: - print(error) \ No newline at end of file + except AssertionError: + print(error) + +def validateInput(input, type): + try: + _ = type(input) + return True + except: + return False \ No newline at end of file