From 2c673f43f3bd2f9243a89b8fd5f6b9dea4130cea Mon Sep 17 00:00:00 2001 From: GauravMS11 <72162639+GauravMS11@users.noreply.github.com> Date: Thu, 1 Oct 2020 00:30:39 +0530 Subject: [PATCH 1/2] Add Document to dictionery.py it is always good practice that to write comments in code. --- exercise/dictionary.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exercise/dictionary.py b/exercise/dictionary.py index 0fe7ec6..9717dc1 100644 --- a/exercise/dictionary.py +++ b/exercise/dictionary.py @@ -1,10 +1,13 @@ +#Creating Dictionery myword = {"centos": "Open source server distribution.", "ubuntu": "Open source desktop distribution", "redhat": "Propriatory OS.", "arch": "Open Source desktop and client distribution." } +#Printing all keys of dictionery print(myword.keys()) print("Check Keys name from above line.") print("Enter your choice name:", end='') +#take input from user to print element of dictionery. tia1 = input() -print(myword[tia1]) \ No newline at end of file +print(myword[tia1]) From f32356fff9d687429f8dd74db3203ddc5af74226 Mon Sep 17 00:00:00 2001 From: GauravMS11 <72162639+GauravMS11@users.noreply.github.com> Date: Thu, 1 Oct 2020 00:43:15 +0530 Subject: [PATCH 2/2] Use of get function in dictionery.py when the user enters the key but the key is not in dictionary, at that time we will show the default message to the user by "get" function. --- exercise/dictionary.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exercise/dictionary.py b/exercise/dictionary.py index 9717dc1..9bb7f4d 100644 --- a/exercise/dictionary.py +++ b/exercise/dictionary.py @@ -10,4 +10,6 @@ print("Enter your choice name:", end='') #take input from user to print element of dictionery. tia1 = input() -print(myword[tia1]) +#use of get functio to access element of dictionery. +print(myword.get(tia1,"No Such Key exist in dictionery")) +#print(myword[tia1])