From d6285950b8b34bb228b349269e05cf1838ef7969 Mon Sep 17 00:00:00 2001 From: MeherChinwala <42064020+MeherChinwala@users.noreply.github.com> Date: Thu, 10 Jan 2019 15:58:26 +0530 Subject: [PATCH] User updates The user can now add additional information to the dictionary only accessible to him for his own reference. The changes won't be permanent and will stay as long as the user keeps using the dictionary. --- interactive-dictionary.py | 48 ++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/interactive-dictionary.py b/interactive-dictionary.py index 9148b0e..a46a0f4 100644 --- a/interactive-dictionary.py +++ b/interactive-dictionary.py @@ -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)