增加联系人: 用户输入姓名、地址、电话等信息,将信息保存在一个列表中列出联系人: 打印输出所有联系人的信息查询联系人: 用户输入联系人姓名,打印输出该联系人的信息修改联系人:用户查询需要修改的用户名,并对其进行修改。删除联系人: 用户输入联系人姓名,从通讯录中删除该联系人'''
@Author: llody
@FilePath: \web\通讯录管理程序.py
'''
persons =[{'name':'llody','address':'四川成都','phone':'1360000000'},{'name':'python','address':'四川成都','phone':'1360000000'},{'name':'go','address':'四川成都','phone':'1360000000'}]
while True:
print("1:查询联系人")print("2:添加联系人")print("3:列出所有联系人")print("4:修改联系人")print("5:删除联系人")print("6:退出程序")
choice = input("请输入【1-6】:")
if choice =='1':
name = input('查询联系人姓名:')for person in persons: #循环读取,将字典中数据读入内存中
if person['name'] == name: #匹配查询联系人与字典中name时候相等print('%s,%s,%s' % (person['name'],person['address'],person['phone']))
else:
print("无姓名为:%s" % name ,"的联系人")elif choice =='2':
name = input('姓名:')
address = input('归属地:')
phone = input('电话号码:')
person = {'name':name,'address':address,'phone':phone}
persons.append(person) #添加如字典内存中
print("已成功添加联系人")elif choice =='3':
for person in persons:
print('%s,%s,%s' % (person['name'],person['address'],person['phone']))
elif choice =='4':
name = input("姓名") #根据name进行查询并修改
for person in persons:
if person['name'] == name:
print("请注意您即将修改名为:%s" % name ,"的联系人,请注意")print('姓名: %s' % person['name'])
person['name'] = input('姓名:')
print('归属地: %s' % person['address'])
person['address'] = input('归属地:')
print('电话号码: %s' % person['phone'])
person['phone'] = input('电话号码:')
print("联系人信息修改成功")break
else:
print("无此联系人")elif choice =='5':
name = input("删除联系人:")for person in persons:
if person['name'] == name:
persons.remove(person) #使用remove函数,删除指定列
print("联系人删除成功")break
else:
print("无此联系人")elif choice =='6':
print("程序已退出")
break
else:
print("输入有误,请重新输入")
用函数方式改写通讯录管理程序
'''
@Author: your name
@FilePath: \web\函数.py
'''
persons =[{'name':'llody','address':'四川成都','phone':'1360000000'},{'name':'python','address':'四川成都','phone':'1360000000'},{'name':'go','address':'四川成都','phone':'1360000000'}]
def query_person():
print("查询联系人")name = input("姓名:")
for person in persons:
if person['name'] == name:
print('%s,%s,%s' %(person['name'],person['address'],person['phone']))
break
else:
print("无此联系人,请重新输入")query_person()
def create_person():
print("添加联系人")name = input("姓名:")
address = input("归属地:")
phone = input("电话号码")
person = {'name':name,'address':address,'phone':phone}
persons.append(person)
print("联系人添加成功")main()
def list_person():
print("列出所有联系人")for person in persons:
print('%s,%s,%s' %(person['name'],person['address'],person['phone']))
main()
def update_person():
print("修改联系人")name = input("姓名:")
for person in persons:
if person['name'] == name:
print("请注意您即将修改名为:%s" % name ,"的联系人,请注意")print('姓名: %s' % person['name'])
person['name'] = input('姓名:')
print('归属地: %s' % person['address'])
person['address'] = input('归属地:')
print('电话号码: %s' % person['phone'])
person['phone'] = input('电话号码:')
print("联系人信息修改成功")main()
break
else:
print("无此联系人,请重新查询输入")main()
def delete_person():
print("删除联系人")name = input("姓名:")
for person in persons:
if person['name'] == name:
persons.remove(person)
print("联系人删除成功")break
else:
print("无此联系人,请确认后输入")data = input("1,继续输入:2,重新查询确认,请选择")
if data == '1':
delete_person()
elif data == '2':
main()
else:
print("输入错误,程序退出")
def git_person():
while True:
print("1:查询联系人")print("2:添加联系人")print("3:列出所有联系人")print("4:修改联系人")print("5:删除联系人")print("6:退出程序")
choice = input("请输入【1-6】:")
return choice
def error_person():
print("输入有误,请重新输入")
def main():
choice = git_person()
if choice == '1':
query_person()
elif choice == '2':
create_person()
elif choice == '3':
list_person()
elif choice == '4':
update_person()
elif choice == '5':
delete_person()
elif choice == '6':
print('程序已退出')
else:
error_person()
main()
'''
@Author: llody
@用类改写通讯录管理系统
@FilePath: \web\addressbook.py
'''
class addressbook:
def __init__(self):
self.persons = [{'name':'llody','address':'四川成都','phone':'1360000000'},{'name':'python','address':'四川成都','phone':'1360000000'},{'name':'go','address':'四川成都','phone':'1360000000'}]
def create_person(self):
name = input("姓名:")
address = input("地址:")
phone = input("电话:")
person = {'name':name,'address':address,'phone':phone}
self.persons.append(person)
def list_person(self):
for person in self.persons:
print('名字:%s,地址:%s,电话:%s'%(person['name'],person['address'],person['phone']))
def query_person(self):
name = input('请输入查询联系人姓名:')for person in self.persons:
if person['name'] == name:
print('名字:%s,地址:%s,电话:%s'%(person['name'],person['address'],person['phone']))
break
else:
print('无此联系人信息')def update_person(self):
name = input("请输入联系人:")for person in self.persons:
if person['name'] == name:
print("请注意,您即将修改的联系人为:%s" %name,"请注意,修改不可逆!!")i = input("继续请输入【y/n】:")
if i == 'y':
print("姓名:%s" %person['name'])
person['name'] = input("姓名修改为:")
print("地址:%s" %person['address'])
person['address'] = input('地址修改为:')
print("电话:%s"%person['phone'])
person['phone'] = input('电话修改为:')
print("修改已完成!!!!")
break
else:
print('退出修改')
break
else:
print('通讯录无此联系人!!!')def delete_person(self):
name = input('请输入需要删除的用户姓名:')
for person in self.persons:
if person['name'] == name:
print("请注意,您即将修改的联系人为:%s" %name,"请注意,修改不可逆!!")i = input("继续请输入【y/n】:")
if i == 'y':
self.persons.remove(person)
print('联系人已成功删除')break
else:
print('已退出删除程序')
break
else:
print('通讯录无此联系人,请确认后再选择!!!')def git_person():
print("欢迎使用通讯录管理程序")
print('1:添加联系人')print('2:列出所有联系人')print('3:查询联系人')print('4:修改联系人信息')print('5:删除联系人')print('6:退出程序')
choice = input("请输入:【1-6】")
return choice
def main_person():
add = addressbook()
while True:
choice = git_person()
if choice == '1':
add.create_person()
elif choice == '2':
add.list_person()
elif choice == '3':
add.query_person()
elif choice == '4':
add.update_person()
elif choice == '5':
add.delete_person()
elif choice == '6':
print('程序已退出')
break
else:
print("输入有误")
main_person()
python通讯录删除功能 python通讯录系统
转载文章标签 python通讯录删除功能 python实现通讯录管理系统 git python 管理程序 文章分类 Python 后端开发
-
iOS添加、删除通讯录 (清空通讯录)
h
代码片段 添加属性 i++