Challenge

Project 1 English Dictionary App

import json


print('HELLO, Hope you are good follow the instruction so i can help you,')
print('Put the option in the choice,')
print('1 to add a new word ')
print('2 to find the meaning of the word')
print('3 to update a word and its meaning')
print('4 to exit')

print('-'*50)

# It will open a file name word.txt.
# we also open a empty dictionay named collection so that we can store word and meaning in collection and it will be stored in word.txt.

swap_w = open('word.txt','w')
collection = {}

json.dump(collection,swap_w)

swap_w.close()


while True :
choice = int(input('Enter your choice : '))

if choice == 1 :

# It will open the word.txt for writing only and save the input given.

swap_w = open('word.txt','w')
add_word = input('Enter a word to add : ')
meaning = input('Enter its meaning : ')
collection[add_word] = meaning
json.dump(collection,swap_w)
swap_w.close()



elif choice == 2 :

# IT will open the word.txt only for reading and will print the meaning of the word entered.
# If the meaning of word doesnt exist in the file it will print a message and say sorry.

swap_r = open('word.txt','r')
carry = json.load(swap_r)
x = input('Enter a word to find its meaning : ')
if x in carry:
print('The meaning of ',x,' is : ',carry[x])
else:
print('Sorry, I cannot find the meaning,')
print('Please check if you have added the word and its meaning.')

elif choice == 3 :

# It will open the word.txt and take an input and will update the previous meaning of the word.

swap_w = open('word.txt','w')
update_word = input('Enter a word to update : ')
meaning = input('Enter a meaning to update : ')
collection[update_word] = meaning
json.dump(collection,swap_w)
swap_w.close()

elif choice == 4 :
print('Thank you very much for visiting')
print('Hope you visit again.')


elif choice > 4 :
print('The choices are from 1 to 4 please read the instructions carefully.')


elif choice < 1 :
print('The choices are from 1 to 4 please read the instructions carefully.')

break

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.