From c57cfda271b777b5975a2b0240701fc4f6abcb06 Mon Sep 17 00:00:00 2001 From: Hiruthic <56349092+hiruthic2002@users.noreply.github.com> Date: Thu, 1 Oct 2020 14:35:36 +0530 Subject: [PATCH 1/2] Updated dictionary.py [Python2] to Python3 Haven't changed the formatting, only rewritten in Python3 syntaxes --- dictionary.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/dictionary.py b/dictionary.py index ea2c9b2..31f2c21 100644 --- a/dictionary.py +++ b/dictionary.py @@ -1,4 +1,3 @@ - global dictionary dictionary = {} @@ -9,53 +8,53 @@ def __init__(self, word, meaning): def add_new(self): dictionary[self.word] = self.meaning - print "Word Successfully Added" + print("Word Successfully Added") def delete_word(self): try: del dictionary[self.word] - print "Word Successfully Deleted" + print("Word Successfully Deleted") except KeyError: - print "The Word Does Not Exist in Dictionary. Try Again!" + print("The Word Does Not Exist in Dictionary. Try Again!") def edit_word(self): try: dictionary[self.word] = self.meaning - print "Word Was Successfully Edited" + print("Word Was Successfully Edited") except KeyError: - print "The Word You Trying To Edit Does Not Exist in Dictionary!" + print("The Word You Trying To Edit Does Not Exist in Dictionary!") def view_word(self): try: - print dictionary[self.word] + print(dictionary[self.word]) except KeyError: - print "The Word is not in Dictionary." + print("The Word is not in Dictionary.") def view_all(self): for i in dictionary.keys(): print(i + " : " + dictionary[i]) def start(): - get_op = raw_input("Add, Delete, Edit, View, View all : ") + get_op = input("Add, Delete, Edit, View, View all : ") if get_op in ["add", "Add"]: - get_word = raw_input("Word to add : ") - get_meaning = raw_input("Meaning : ") + get_word = input("Word to add : ") + get_meaning = input("Meaning : ") new = Dict(get_word, get_meaning) new.add_new() elif get_op in ["delete", "Delete"]: - get_word_to_del = raw_input("Word to delete : ") + get_word_to_del = input("Word to delete : ") delete = Dict(get_word_to_del, None) delete.delete_word() elif get_op in ["edit", "Edit"]: - get_word_to_edit = raw_input("Word to edit : ") - get_new_meaning = raw_input("New meaning : ") + get_word_to_edit = input("Word to edit : ") + get_new_meaning = input("New meaning : ") mean = Dict(get_word_to_edit, get_new_meaning) mean.edit_word() elif get_op in ["view", "View"]: - get_word_to_view = raw_input("Word to view : ") + get_word_to_view = input("Word to view : ") view = Dict(get_word_to_view, None) view.view_word() @@ -64,15 +63,15 @@ def start(): nothing.view_all() else: - print "Invalid Input. Try again!" + print("Invalid Input. Try again!") def end(): quit() def main(): while True: - s_or_e = raw_input("Start or End : ") - if s_or_e == "Start": + s_or_e = input("Start or End : ") + if s_or_e.lower() == "start": start() print(" ") continue @@ -82,4 +81,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() From 3bac65e7b330b7538887fed34b764520b31a5fe6 Mon Sep 17 00:00:00 2001 From: Hiruthic <56349092+hiruthic2002@users.noreply.github.com> Date: Fri, 2 Oct 2020 06:50:06 +0530 Subject: [PATCH 2/2] Update dictionary.py --- dictionary.py | 144 ++++++++++++++++++++++++++------------------------ 1 file changed, 74 insertions(+), 70 deletions(-) diff --git a/dictionary.py b/dictionary.py index 31f2c21..659b559 100644 --- a/dictionary.py +++ b/dictionary.py @@ -1,84 +1,88 @@ global dictionary dictionary = {} + class Dict: - def __init__(self, word, meaning): - self.word = word - self.meaning = meaning - - def add_new(self): - dictionary[self.word] = self.meaning - print("Word Successfully Added") - - def delete_word(self): - try: - del dictionary[self.word] - print("Word Successfully Deleted") - except KeyError: - print("The Word Does Not Exist in Dictionary. Try Again!") - - def edit_word(self): - try: - dictionary[self.word] = self.meaning - print("Word Was Successfully Edited") - except KeyError: - print("The Word You Trying To Edit Does Not Exist in Dictionary!") - - def view_word(self): - try: - print(dictionary[self.word]) - except KeyError: - print("The Word is not in Dictionary.") - - def view_all(self): - for i in dictionary.keys(): - print(i + " : " + dictionary[i]) + def __init__(self, word, meaning): + self.word = word + self.meaning = meaning + + def add_new(self): + dictionary[self.word] = self.meaning + print("Word Successfully Added") + + def delete_word(self): + try: + del dictionary[self.word] + print("Word Successfully Deleted") + except KeyError: + print("The Word Does Not Exist in Dictionary. Try Again!") + + def edit_word(self): + try: + dictionary[self.word] = self.meaning + print("Word Was Successfully Edited") + except KeyError: + print("The Word You Trying To Edit Does Not Exist in Dictionary!") + + def view_word(self): + try: + print(dictionary[self.word]) + except KeyError: + print("The Word is not in Dictionary.") + + def view_all(self): + for i in dictionary.keys(): + print(i + " : " + dictionary[i]) + def start(): - get_op = input("Add, Delete, Edit, View, View all : ") - if get_op in ["add", "Add"]: - get_word = input("Word to add : ") - get_meaning = input("Meaning : ") - new = Dict(get_word, get_meaning) - new.add_new() - - elif get_op in ["delete", "Delete"]: - get_word_to_del = input("Word to delete : ") - delete = Dict(get_word_to_del, None) - delete.delete_word() - - elif get_op in ["edit", "Edit"]: - get_word_to_edit = input("Word to edit : ") - get_new_meaning = input("New meaning : ") - mean = Dict(get_word_to_edit, get_new_meaning) - mean.edit_word() - - elif get_op in ["view", "View"]: - get_word_to_view = input("Word to view : ") - view = Dict(get_word_to_view, None) - view.view_word() - - elif get_op in ["view all", "View All", "View all"]: - nothing = Dict(None, None) - nothing.view_all() - - else: - print("Invalid Input. Try again!") + get_op = input("Add, Delete, Edit, View, View all : ") + if get_op in ["add", "Add"]: + get_word = input("Word to add : ") + get_meaning = input("Meaning : ") + new = Dict(get_word, get_meaning) + new.add_new() + + elif get_op in ["delete", "Delete"]: + get_word_to_del = input("Word to delete : ") + delete = Dict(get_word_to_del, None) + delete.delete_word() + + elif get_op in ["edit", "Edit"]: + get_word_to_edit = input("Word to edit : ") + get_new_meaning = input("New meaning : ") + mean = Dict(get_word_to_edit, get_new_meaning) + mean.edit_word() + + elif get_op in ["view", "View"]: + get_word_to_view = input("Word to view : ") + view = Dict(get_word_to_view, None) + view.view_word() + + elif get_op in ["view all", "View All", "View all"]: + nothing = Dict(None, None) + nothing.view_all() + + else: + print("Invalid Input. Try again!") + def end(): - quit() + quit() + def main(): - while True: - s_or_e = input("Start or End : ") - if s_or_e.lower() == "start": - start() - print(" ") - continue + while True: + s_or_e = input("Start or End : ") + if s_or_e.lower() == "start": + start() + print(" ") + continue - else: - end() + else: + end() if __name__ == "__main__": - main() + main()