import json
dic0 = dict()
def create_file(count):
if count == 0:
f1 = open('word.txt', 'w')
dic0['Juggernaut'] = 'massive force, campaign, movement, or object that crushes whatever is in its path.'
dic0['Winsome'] = 'pleasing or cheerful.'
dic0['Opine'] = 'to express an opinion'
dic0['Intemperate'] = 'having extreme conditions or having or showing a lack of emotional calmness or control.'
dic0['Debilitating'] = 'causing serious impairment of strength or ability to function.'
json.dump(dic0,f1)
return f1
else:
f1 = open('word.txt', 'w')
return f1
def main_menu():
val = int(input('''
1. New word
2. Find the meaning
3. Update a word
4. Show the contents of the current dictionary
5. Exit '''))
return val
def add_word():
word = input('Please enter the word: ').title()
meaning = input('Please enter the meaning of the word: ')
dic0[word] = meaning
f = create_file(1)
json.dump(dic0, f)
f.close()
def find_word(word):
f = open('word.txt', 'r')
dic0 = json.load(f)
print(f'The meaning of {word}: {dic0[word]}')
def update_word(word):
f = open('word.txt', 'r')
dic0 = json.load(f)
if word in dic0:
meaning = input('Please enter the meaning of the word: ')
dic0[word] = meaning
f = create_file(1)
json.dump(dic0, f)
f.close()
else:
print('Word does not exist and please add the word into the dictionary: ')
add_word()
def edit_menu():
val = main_menu()
if val > 0 and val <= 5:
if val == 1:
add_word()
edit_menu()
elif val == 2:
word = input('Please enter the word to find the meaning off: ').title()
find_word(word)
edit_menu()
elif val == 3:
word = input('Please enter the word that need to be updated: ').title()
update_word(word)
edit_menu()
elif val == 4:
print('The contents of current dictionary are: ')
f = open('word.txt', 'r')
dic0 = json.load(f)
print(dic0)
edit_menu()
else:
print('exit')
else:
print('Please enter the correct number')
count = 0
create_file(count)
edit_menu()