# 做一个名片管理系统
# 要求有姓名,年纪,电话
# 要求可以增删改查
print('欢迎进入名片系统')
print('='*100)
print('1.查看')
print('2.增加')
print('3.删除')
print('4.修改')
print('5.退出')
list_card = []
while True:
choose = input('请选择你的操作:').strip()
#查看
if choose == '1':
for i in list_card:
print('名字:%s,年纪%s,电话:%s' % (i['name'],i['age'],i['phone']))
name=input('请输入你要查看的名片').strip()
j = 0
if list_card:
while j < len(list_card):
if name in list_card[j].values():
print('名字:%s年纪:%s电话:%s' %(list_card[j]['name'],list_card[j]['age'],list_card[j]['phone']))
j +=1
else:
print('空')
break
else:
print('空')
#增加
elif choose == '2':
name = input('请输入要增加的联系人名字:').strip()
age = input('请输入要增加的联系人年纪:').strip()
phone = input('请输入要增加的联系人电话:').strip()
list_card.append({
'name':name,
'age':age,
'phone':phone
})
print('添加成功')
#删除
elif choose == '3':
name = input('请输入你要删除的名片').strip()
j = 0
while j < len(list_card):
if name in list_card[j].values():
j +=1
list_card.remove(list_card[j-1])
print('删除成功')
#修改
elif choose == '4':
name = input('请输入你要修改的名片').strip()
j = 0
while j < len(list_card):
if name in list_card[j].values():
j += 1
print('1.修改名字')
print('2.修改年纪')
print('3.修改电话')
choose1 = input('请输入你要修改的选项').strip()
if choose1 == '1':
name = input('请输入你要修改的名字:').strip()
if name:
list_card[j - 1]['name'] = name
else:
print('输入名字为空不能修改名片')
break
if choose1 == '2':
age = input('请输入你要修改的年纪:').strip()
if age:
list_card[j - 1]['age'] = age
else:
print('输入年纪为空不能修改名片')
break
if choose1 == '3':
phone = input('请输入你要修改的电话:').strip()
if phone:
list_card[j-1]['phone'] = phone
else:
print('输入电话为空不能修改名片')
break