Python 增删改查
程序员文章站
2022-07-14 22:58:07
...
# -*- coding: UTF-8 -*-
name = []
print ('键入1:新增人名')
print ('键入2:删除人名')
print ('键入3:修改人名')
print ('键入4:查询人名')
print ('键入5:退出')
ipt = int(input('请输入数字:'))
while True:
if ipt == 1:
name.append(input('请输入新增人名:'))
print (name)
ipt = int(input('请输入数字:'))
elif ipt == 2:
a = input('请输入删除人名:')
if a in name:
name.remove(a)
print(name)
ipt = int(input('请输入数字:'))
else:
print('姓名不存在')
ipt = int(input('请输入数字:'))
elif ipt == 3:
a,b = input('请输入修改人名:'),input('请输入要替换人名:')
if a in name:
name.remove(a)
name.append(b)
print(name)
ipt = int(input('请输入数字:'))
else:
print('姓名不存在')
ipt = int(input('请输入数字:'))
elif ipt == 4:
a = input('请输入要查询的人名:')
if a in name:
print ('存在')
print(name)
ipt = int(input('请输入数字:'))
else:
print('不存在')
ipt = int(input('请输入数字:'))
elif ipt == 5:
print('结束')
break
else:
print('请输入整数1-5 任意一个')
ipt = int(input('请输入数字:'))
上一篇: python三级菜单
下一篇: python 增删改查