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
31 changes: 19 additions & 12 deletions interactive-dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#Loading the json data as python dictionary
#Try typing "type(data)" in terminal after executing first two line of this snippet
data = json.load(open("data.json"))
data = json.load(open("dictionary.json"))

#Function for retriving definition
def retrive_definition(word):
Expand Down Expand Up @@ -34,17 +34,24 @@ def retrive_definition(word):
return ("The word doesn't exist, yet.")
else:
return ("We don't understand your entry. Apologies.")
flag = True
while(flag):
#Input from user
word_user = input("Enter a word: ")

#Input from user
word_user = input("Enter a word: ")
#Retrive the definition using function and print the result
output = retrive_definition(word_user)

#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)

#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)
ask = input("\nDo you want to search another word? [y/n]: ")
if(ask.lower() == 'y' or ask.lower() == 'yes'):
flag = True
else:
flag = False