Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 37 additions & 11 deletions interactive-dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,45 @@ def retrive_definition(word):
return data[get_close_matches(word, data.keys())[0]]
elif (action == "n"):
return ("The word doesn't exist, yet.")
action_2 = raw_input("Do you want to update the existing dictionary? [y or n]:")


if(action_2 == 'y'):

key = raw_input("Enter the word:")

value = raw_input("Enter the meaning :")

data.update({key : value})

return ("updated!")

elif (action_2 == 'n'):

return ("Okay!")
else:
return ("Please enter a valid response!")

else:
return ("We don't understand your entry. Apologies.")
toexit = 0

while(toexit != 1):
#Input from user
word_user = input("Enter a word: ")

#Retrive the definition using function and print the result
output = retrive_definition(word_user)

#If a word has more than one definition, print them recursively
if type(output) == list:
for item in output:
print("-",item)
#For words having single definition
else:
print("-",output)
toexit = input("Do you want to exit? [1 or 0]")

#Input from user
word_user = input("Enter a word: ")

#Retrive the definition using function and print the result
output = retrive_definition(word_user)
print ("Thanks for using this dictionary!")

#If a word has more than one definition, print them recursively
if type(output) == list:
for item in output:
print("-",item)
#For words having single definition
else:
print("-",output)