Professional Documents
Culture Documents
#Adding a contact
if(inp == 1):
name = raw_input("Enter your friend name: ")
l.append(name)
print("Contact Added \n\n")
#Modifying a contact if the entered name is present in the list
elif(inp == 2):
name = raw_input("Enter the name which is to be modified: ")
if(name in l):
n = raw_input("Enter the new name: ")
a=l.index(name)
l[a]= n
print("name Modified\n\n")
else:
print("The name is not present in the contact list")
#Deleting a contact if the entered name is present in the dictionary
elif(inp == 3):
name = raw_input("Enter the name of friend whose contact is to be deleted:
")
if(name in l):
l.remove(name)
print("Contact Deleted\n\n")
else:
print("This friend's name is not present in the contact list")
#Displaying all entries in the dictionary
elif(inp == 4):
print("All entries in the contact")
for a in range(0,len(l)):
print(a,"\t\t",l[a])
print("\n\n\n")
#Searching a friend name in the dictionary
elif(inp == 5):
name = raw_input("Enter the name to search: ")
if(name in l):
print("The friend",name,"is present in the list\n\n")
else:
print("The friend",name,"is not present in the list\n\n")
#Displaying the dictionary in the sorted order of the names
elif(inp == 6):
print("Sorted List")
l.sort()
for a in range(0,len(l)):
print(a,"\t\t",l[a])
print("\n\n\n")
#Exit the while loop if user enters 7
elif(inp == 7):
break
#Displaying the invalid choice when any other values are entered
else:
print("Invalid Choice. Please try again\n")