16-is-dead/clean_input.py

40 lines
1.2 KiB
Python

"""clean_input"""
import sys
import game
# message needs to be a string that is printed for user instruction. options is a list of viable inputs
def io(message: str, options: list) -> str:
while True:
try:
i = str(input(message))
except (ValueError, NameError):
print("Eingabe nicht gültig, bitte wiederhole deine Eingabe.")
if i in options:
return i
break
else:
# try:
# print('Noch nicht ganz richtig. Hast du deine Auswahl auch richtig geschrieben?')
#
# except(i == 'q' or i == 'r'):
#
# if i == 'q':
# print("Spiel wird beendet...")
# sys.exit()
#
# if i == 'r':
# print("Spiel wird neu gestartet...")
# game.main()
if i == "q":
print("Spiel wird beendet...")
sys.exit()
elif i == "r":
print("Spiel wird neu gestartet...")
game.main()
else:
print('Noch nicht ganz richtig. Hast du deine Auswahl auch richtig geschrieben?')