You are on page 1of 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