0% found this document useful (0 votes)
8 views4 pages

Python Dictionary Management Program

The document outlines a menu-driven Python program for creating and managing a dictionary of words and their meanings. It includes functionalities to add, delete, search, and modify entries, as well as display the dictionary as a set. The program's algorithm and flowchart are provided, along with a sample output demonstrating its usage.

Uploaded by

sruthinath
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Python Dictionary Management Program

The document outlines a menu-driven Python program for creating and managing a dictionary of words and their meanings. It includes functionalities to add, delete, search, and modify entries, as well as display the dictionary as a set. The program's algorithm and flowchart are provided, along with a sample output demonstrating its usage.

Uploaded by

sruthinath
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

AIM: To create a dictionary of elements having words and their corresponding meanings

Develop a menu driven program that offers user with the following options

[Link] a new word to the dictionary.

[Link] a word from the dictionary.

[Link] for the meaning of word .

[Link] the meaning of word.

[Link] all the words in the dictionary as sets.

ALGORITHM:

STEP1: Start

STEP2: Create an empty dictionary as meaning.

STEP3:Get the number of key value pairs.

STEP4:Get the keys and values using for loop and add the keys and values using
dict[key]=value.

STEP5:Get the new key and value to be added and add the key value pair using
dict[key]=value.

STEP6:Get the word to be deleted as d.

STEP7: if d in meaning ,assign deleted_word as [Link](d) and print word deleted


,deleted_word else go to step8 .

STEP8:else print word not found.

STEP 9: get the word to be searched as search.

STEP 10:if search in meaning store it in s and print word found,s else go to step 11

STEP 11 :else print word not found.

STEP12:get key and value to be modified as mod and mod1.

STEP13: use dict[key]=value to modify the word.

STEP14:use set([Link]()) to convert the words in dictionary into a set.

STEP15: stop

FLOWCHART:
START

Create an empty dictionary as


meaning

Get the number of key


value pairs.

for i in
range(n+1)

Get the new key value pair to be added .

Use dict[key]=value to add new key value pair

Get the word to be deleted as d.

no
If d in
Print word not found.
meaning

yes

Deleted_word=[Link](d)

Print word deleted,deleted_word

get the word to be searched


as search

If search in no Print word not


meaning
found.

yes

Store it in s

Print word found,s

Get key and value to be modified


as mod and mod1.

Use dict[key]=value to modify.

Print meaning

Use set([Link]()) function to convert


dictionary to set .

stop Pop
PROGRAM:

#creating a dictionary

meaning={}
n=int(input("enter number of key value pairs:"))
for i in range(n+1):
key=input("enter a key:")
value=input("enter a value:")
meaning[key]=value

# adding new value to dictionary

m=input("enter a new key:")


n=input("enter a new value:")
meaning[m]=n

#deleting a value in a dictionary

d=input("enter key to be deleted:")


if d in meaning:
deleted_value=[Link](d)
print("word deleted",deleted_value)
else:
print("word not found")

#searching a value in dictionary

search=input("enter a key to be searched:")


if search in meaning:
s=meaning[search]
print("word found",s)
else:
print("word not found")

#modifying a value in dictionary

mod=input("enter a key to be modified:")


mod1=input("enter modified value:") meaning[mod]=mod1
print(meaning)

#using set function

set1=set([Link]())
print(set1)

OUTPUT
enter number of key value pairs:2
enter a key:joy
enter a value:happiness
enter a key:huge
enter a value:vast
enter a key:small enter a value:tiny
enter a new key:ill
enter a new value:unwell
enter key to be deleted:huge
word deleted vast
enter a key to be searched:joy
word found happiness
enter a key to be modified:ill
enter modified value:sick
{'joy': 'happiness', 'small': 'tiny', 'ill': 'sick'}
{('small', 'tiny'), ('ill', 'sick'), ('joy', 'happiness')}

RESULT:
Thus the python program to create a dictionary and add ,modify and search a word
and convert the dictionary to a set has been implemented.

You might also like