编程语言
首页 > 编程语言> > 13、通讯录管理程序

13、通讯录管理程序

作者:互联网

# 创建一个全局列表容器来存储联系人字典
persons = []

while True:
	# 程序菜单
    print('1. 创建联系人')
    print('2. 列出所有联系人')
    print('3. 查询联系人')
    print('4. 删除联系人')
    print('5. 退出程序')
    choice = input('请输入选项(1-5):')   

	# 1.创建联系人
    if choice == '1':
        name = input('name: ')
        address = input('address: ')
        phone = input('phone: ')
        person = {'name': name,  'address': address, 'phone': phone}
        persons.append(person)
	
	# 2.列出所有联系人 
    elif choice == '2':
        for person in persons:
            print('%s,%s,%s \n\n' % (person['name'], person['address'], person['phone']))


	# 3. 查询联系人
    elif choice == '3':
        name = input('name: ')
        for person in persons:
            if person['name'] == name:
                print('%s,%s,%s \n\n' % (person['name'], person['address'], person['phone']))

	# 4.删除联系人
    elif choice == '4':
        name = input('name: ')
        for person in persons:
            if person['name'] == name:
                persons.remove(person)
                break

	# 5. 退出程序
    elif choice == '5':
        break

	# 6.无效选项
    else:
        print('你输入了无效选项!\n\n')        

标签:13,name,管理程序,联系人,phone,person,通讯录,print,input
来源: https://www.cnblogs.com/tiansz/p/16389132.html