0% found this document useful (0 votes)
486 views2 pages

Program 7. Menu Driven Code - Dictionary AIM: Program Coding: Def Add (D)

The document describes a menu-driven program that stores subscriber names and phone numbers in a dictionary. The menu allows the user to perform operations like adding, viewing, modifying, and deleting entries from the dictionary. User-defined functions are created to handle each operation - add() adds a new entry, show() displays the dictionary, modify() updates an existing name, and delete() removes an entry. The program runs in a loop, displaying the menu and calling the appropriate function based on the user's input until they choose to exit.

Uploaded by

vimala
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)
486 views2 pages

Program 7. Menu Driven Code - Dictionary AIM: Program Coding: Def Add (D)

The document describes a menu-driven program that stores subscriber names and phone numbers in a dictionary. The menu allows the user to perform operations like adding, viewing, modifying, and deleting entries from the dictionary. User-defined functions are created to handle each operation - add() adds a new entry, show() displays the dictionary, modify() updates an existing name, and delete() removes an entry. The program runs in a loop, displaying the menu and calling the appropriate function based on the user's input until they choose to exit.

Uploaded by

vimala
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
You are on page 1/ 2

PROGRAM 7.

MENU DRIVEN CODE – DICTIONARY

AIM
WAP to store subscriber name and phone number in a dictionary and perform the
following operations as menu drive code using UDFs:
i) ADD
ii) VIEW iii)MODIFY NAME
iv)DELETE
v) EXIT
PROGRAM CODING:
def add(d):
name=input("enter the name:")
ph=int(input("enter the phone number:"))
d[ph]=name
def Delete(d):
dph=int(input("enter the phone number to be removed:"))
if dph in d:
d.pop(dph) #del d[dph]
else:
print("Phone number not present")
def modify(d,mph):
if mph in d:
n=input("Enter a new name")
d[mph]=n
else:
print("phone number not present")

def show(d):
print("current status of the dictionay:")
print(d)

print("MENU \n 1.ADD\n 2. VIEW \n 3.MODIFY NAME \n 4.DELETE \n 5. EXIT")


d={}
while True:
ch=int(input("enter choice:"))
if ch==1: add(d)
elif ch==2: show(d)
elif ch==3:
mod=int(input("enter the phone no. to be modified"))
modify(d,mod)
elif ch==4: Delete(d)
elif ch==5:
print("program terminated")
break
else: print("wrong choice")
OUTPUT
MENU
1.ADD
2. VIEW
3.MODIFY NAME
4.DELETE
5. EXIT
enter choice:1
enter the name:raj
enter the phone number:9791138390
enter choice:1
enter the name:ram
enter the phone number:9444133110
enter choice:2
current status of the dictionay:
{9791138390: 'raj', 9444133110: 'ram'}
enter choice:3
enter the phone no. to be modified9444133110
Enter a new namerambalaji
enter choice:2
current status of the dictionay:
{9791138390: 'raj', 9444133110: 'rambalaji'}
enter choice:4
enter the phone number to be removed:9791138390
enter choice:2
current status of the dictionay:
{9444133110: 'rambalaji'}
enter choice:3
enter the phone no. to be modified9791138390
phone number not present
enter choice:5
program terminated'''

You might also like