python列表操作例程之名片管理
运用列表的添加、删除、修改、查询等命令,创建了
def welcome():————欢迎函数
def add_info():————添加函数
def delete_info():————删除函数
def modify_info():————修改函数
def search_info():————搜索函数运行效果如下:
源代码如下:
info_list = [] password = "506506" def main(): while True: welcome() command=int(input()) if command == 1: add_info() elif command == 2: delete_info() elif command == 3: modify_info() elif command == 4: search_info() elif command == 5: view_info() elif command == 6: quit_info() break else: print("[ERROR]:输入错误,请重新输入!") def welcome(): print("---------------------") print("--- 1. 添加名片 -----") print("--- 2. 删除名片 -----") print("--- 3. 修改名片 -----") print("--- 4. 查询名片 -----") print("--- 5. 显示全部 -----") print("--- 6. 退出系统 -----") print("--请输入需要指定的操作: ", end="") def add_info(): name = input("请输入姓名:") age = input("请输入年龄:") gender = input("请输入性别:") info_list.append([name,age,gender]) print("[INFO]:存储成功!") def delete_info(): name = input("请输入姓名:") for info in info_list: if name in info: info_list.remove([info]) print("[INFO]:删除成功!") break else:print("[info]:系统查无此人!") def modify_info(): name = input("请输入姓名:") for info in info_list: if name in info: newname = input("请重新输入姓名:") newage = input("请重新输入年龄:") newgender = input("请重新输入性别:") info_list[info_list.index(info)]=[newname,newage,newgender] print("[INFO]:修改成功!") break else: print("[ERROR]:系统查无此人") def search_info(): name = input("请输入姓名:") for info in info_list: if name in info: print("[INFO]:查询成功,结果如下:",end=" ") print(info) break else: print("[ERROR]:系统内查无此人!") def view_info(): pwd = input("请输入管理员密码:") if pwd == password: for info in info_list: print(info) else: print("[ERROR]:密码错误!") def quit_info(): print("[INFO]:谢谢您的使用,再见!") if __name__ == ‘__main__‘ : main()
相关推荐
sifeimeng 2020-06-21
阿斌Elements 2020-05-05
songerxing 2020-05-03
yixiaoqi00 2020-04-22
要啥自行车一把梭 2020-04-17
随心而作 2020-04-07
JayFighting 2020-04-07
80327065 2020-03-09
lhxxhl 2020-03-06
woxmh 2020-03-04
hgzhang 2020-02-18
时光如瑾雨微凉 2020-02-02
winmeanyoung 2020-01-29
typhoonpython 2020-01-12
sofast 2020-01-08
KaiZhaoKZ 2019-12-29
snowpage 2014-07-10