I'm new to python (a couple weeks) and the first project i'm working on is creating an application to more easily study Russian verb conjugations. Right now I'm working on the functions of the program itself, once I have that I will dive into the GUI.
The idea is that when the user loads the program they can choose to create/modify sets or study them. From there they either choose which study set to study or begin creating a study set. So far the only function I have is one that returns a random verb and conjugate form (this part of my code works, just giving some context).
import random
import json
test_verbs = [{
'verb': 'изучать',
'defintion': 'to study in depth',
'я': 'изучаю',
'ты': 'изучаешь',
'он': 'изучает',
'вы': 'изучаете',
'мы': 'изучаем',
'они': 'изучают',
'informal imperative': 'изучай',
'formal_imperative': 'изучайте',
},
{'verb': 'говорить',
'definition': 'to talk',
'я': 'говорю',
'ты': 'говоришь',
'он': 'говорит',
'вы': 'говорите',
'мы': 'говорим',
'они': 'говорят',
'informal imperative': 'говори',
'formal imperative': 'говорите'}]
#function to randomly generate a verb and a pronoun, conjugation pair
def random_conjugation(verb_list):
random_verb = random.choice(verb_list)
print( f"the verb is {random_verb['verb']}" )
conjugation_dict_fields = ['я', 'ты', 'он', 'вы', 'мы', 'они']
random_form = random.choice( conjugation_dict_fields )
print( f"What is the {random_form} form of the verb?" )
print( random_verb[random_form] )
#function test
random_conjugation(test_verbs)
The problem I'm trying to tackle right now is getting my lists into a .json file so the user created lists can be saved.
My initial attempt was this, but it clearly did not work:
def create_new_list(list_name):
list_name = []
filename = f'{list_name}.json'
print("type 'q' to stop adding entries to the list")
while True:
verb = input("Type a new verb: ")
list_name.append(verb)
if verb == 'q':
break
with open(filename, 'w') as f:
json.dump(list_name, f)
I don't have my list formatted in a way that matches my verb dictionary storage structure, but i figured it would be easier for you guys to help me without having a complicated dictionary and Russian pronouns get in the way...
I know my solution does not work, I clearly am missing a core concept here, but it was my best attempt. I thought it would be a good solution because the user creates the name of the new list, and that list name also becomes the name_of_the_file.json
Maybe there's a simple solution here, or maybe I'm going about this in the completely wrong way. Any help is appreciated here.