Bei "while" break und continue vermeiden, aber Einrückung "flach" halten
Verfasst: Samstag 5. Dezember 2020, 19:23
Hallo, hat jemand eine Idee, wie ich das Schnipsel umschreiben könnte, so dass kein `continue` gebraucht wird? Danke schonmal
Code: Alles auswählen
my_dictionary = {}
def a_func(sk: dict):
pass
def n_func(sk: dict):
pass
def h_func(sk: dict):
options = {"a": a_func, "n": n_func}
cont = True
invalid = False
while cont:
if invalid:
print("Das war eine ungültige Eingabe. Bitte nochmal.")
invalid = False
print("Bitte wähle: a n e")
input1 = input()
if len(input1) == 0:
invalid = True
continue
ch = input1[0]
if ch == "e":
cont = False
continue
if ch not in options:
invalid = True
continue
options[ch](sk)
h_func(my_dictionary)