word = {} def train(): with (open("vocab.txt", "r+")) as vocab: for line in vocab: word[line] = vocab.readline() try: while True: if input(f"what is the translation of '{word[0]}'? ") in word[1]: print("correct!") break else: print("incorrect, try again") except KeyError: print("no such word in the library!") print() def save_vocab(): ger = input("enter a german word: ") en = input("enter an english translation: ") with (open("vocab.txt", "w")) as vocab: vocab.write(f"{ger}, {en}") while True: print("1. Add a new word") print("2. Train") print("3. Quit") user_inp = input() if user_inp == "1": save_vocab() if user_inp == "2": train() if user_inp == "3": break