"""This module handles most user inputs.""" __author__ = "" __credits__ = "" __email__ = "" import sys def io_str(message: str, options: list) -> str: """ This method checks if a user input fits the options. It also handles 'r' for restarting and 'q' for quitting. :param message: message needs to be a string that is printed for user instruction. :param options: options is a list of viable inputs. :return: Cleaned user input """ while True: try: i = str(input(message)) except (ValueError, NameError): i = 0 print("Eingabe nicht gültig, bitte wiederhole deine Eingabe.") if i in options: return i else: if i == "q": print( "---------------------\nSpiel wird beendet...\n---------------------") sys.exit() elif i == "r": print( "---------------------\nSpiel wird neu gestartet...\n---------------------") quartett.main() else: print('Noch nicht ganz richtig. Hast du deine Auswahl auch richtig geschrieben?') def io_int(message: str) -> int: """ This method checks if a user input is an integer >1. It also handles 'r' for restarting and 'q' for quitting. :param message: message needs to be a string that is printed for user instruction :return: Integer >1 """ while True: unfiltered_input = input(message) if unfiltered_input == "q": print("---------------------\nSpiel wird beendet...\n---------------------") sys.exit() elif unfiltered_input == "r": print( "---------------------\nSpiel wird neu gestartet...\n---------------------") #quartett.main() try: i = int(unfiltered_input) if i >= 1: return i else: print('Bitte gib eine ganze Zahl größer als 0 ein. ') except (ValueError, NameError): print("Eingabe nicht gültig, bitte wiederhole deine Eingabe.") def io_list(message: str, options: list): """ check card selection :param message: 1a :param options: [{'id': 3, 'number': 0, 'letter': 'd'}, {'id': 9, 'number': 1, 'letter': 'b'}] :return: """ while True: try: i = str(input(message)) except (ValueError, NameError): i = 0 print("Eingabe nicht gültig, bitte wiederhole deine Eingabe.") if i in options: return i else: if i == "q": print( "---------------------\nSpiel wird beendet...\n---------------------") sys.exit() elif i == "r": print( "---------------------\nSpiel wird neu gestartet...\n---------------------") quartett.main() else: print('Noch nicht ganz richtig. Hast du deine Auswahl auch richtig geschrieben?') def define_card_stack(): """ :return: """ for i in range(4): for l in "abcdefgh": d = {"id": x, "number": i, "letter": l} card_stack.append(d) x += 1