56 lines
1.1 KiB
Python
56 lines
1.1 KiB
Python
|
commands = {}
|
||
|
|
||
|
def add_command(name):
|
||
|
def decorator(f):
|
||
|
commands[name] = f
|
||
|
return f
|
||
|
return decorator
|
||
|
|
||
|
@add_command("erstellen")
|
||
|
def erstelleWörterbuch():
|
||
|
wb = {}
|
||
|
for i in range(10):
|
||
|
native = input()
|
||
|
translated = input()
|
||
|
wb[native] = translated
|
||
|
return wb
|
||
|
|
||
|
@add_command("suchen")
|
||
|
def findeÜbersetzung(wb, wort):
|
||
|
return wb.get(wort)
|
||
|
|
||
|
@add_command("auflisten")
|
||
|
def erstelleIndex(wb):
|
||
|
return list(wb.keys())
|
||
|
|
||
|
@add_command("existiert")
|
||
|
def existiertÜbersetzung(wb, übersetzung):
|
||
|
return übersetzung in list(wb.values())
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
import inspect
|
||
|
|
||
|
wörterbuch = {}
|
||
|
while True:
|
||
|
print("Mögliche Aktionen:")
|
||
|
print(", ".join(list(commands.keys())))
|
||
|
print("Geben sie eine Aktion an")
|
||
|
aktion = input()
|
||
|
if aktion not in commands.keys():
|
||
|
print("Aktion nicht verfügbar")
|
||
|
continue
|
||
|
ag = []
|
||
|
for arg in list(inspect.getargspec(commands[aktion]).args):
|
||
|
if arg == "wb":
|
||
|
ag.append(wörterbuch)
|
||
|
else:
|
||
|
print("argument", arg)
|
||
|
ag.append(input())
|
||
|
|
||
|
r = commands[aktion](*ag)
|
||
|
|
||
|
if aktion == "erstellen":
|
||
|
wörterbuch = r
|
||
|
else:
|
||
|
print(r)
|