国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python列表使用實(shí)現(xiàn)名字管理系統(tǒng)

2020-02-16 01:00:23
字體:
供稿:網(wǎng)友

本文實(shí)例為大家分享了python列表使用實(shí)現(xiàn)名字管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

實(shí)現(xiàn)的功能代碼如下:

# 名字管理系統(tǒng) 列表的使用print("="*50)print("1:添加名字")print("2:修改名字")print("3:查詢名字")print("4:刪除名字")print("5:退出")print("="*50)names = [] while True: num = int(input("請輸入要操作的序號:")) # input獲取到的是str,要轉(zhuǎn)換為Int  if num == 1: name_add = input("請輸入要添加的名字:") names.append(name_add) print(names) elif num == 2: name_edit1 = input("請輸入要修改的原始名字") # 法一: # if name_edit1 in names: # for i in range(len(names)): #  if name_edit1 == names[i]: #  name_edit2 = input("請輸入要修改為的名字:") #  names[i] = name_edit2 #  print("修改成功!") # else: # print("查無此人")  # 法二: find_name = 0 # 默認(rèn)沒找到 for i in range(len(names)):  if name_edit1 == names[i]:  name_edit2 = input("請輸入要修改為的名字:")  names[i] = name_edit2  print("修改成功!")  find_name = 1 if find_name = 0:  print("查無此人") elif num == 3: name_select = input("請輸入要查詢的名字:") if name_select in names:  print("找到了要查找的人") else:  print("查無此人") elif num == 4: name_del = input("請輸入要進(jìn)行刪除的名字:") if name_del in names:  names.remove(name_del)  print("刪除成功!") else:  print("查無此人,無法進(jìn)行刪除") elif num == 5: break else: print("輸入錯誤!")

小編再為大家分享另一段用python中列表實(shí)現(xiàn)名字管理系統(tǒng)的代碼:

1、打印功能提示
2、獲取用戶輸入
3、根據(jù)用戶的輸入選擇相應(yīng)的功能進(jìn)行實(shí)現(xiàn)

#打印提示print("="*50)print("names_manage_systme")print("1、add a new name")print("2、delete a name")print("3、modify a name")print("4、search a name")print("5、quit!")print("="*50)#存儲用戶姓名names = []while True:#獲取用戶輸入 user_input_num = int(input("please input the number you need:"))#功能實(shí)現(xiàn) if user_input_num == 1: #增加 new_name = input("please input the new name that you need to add:") names.append(new_name) print(names) elif user_input_num == 2: #刪除 del_name = input("please input the new name that you need to delete:") names.remove(del_name) print(names) elif user_input_num == 3: #改 modify_name = input("please input the new name that you need to modify:") after_modify_name = input("please input the new name :") length = len(names) modify_name_index = 0 i = 0 while i < length:  if modify_name == names[i]:  modify_name_index = i  break  i += 1 names[modify_name_index] = after_modify_name print(names) elif user_input_num == 4: #查找 search_name = input("please input the new name that you need to search:") length = len(names) search_name_index = 0 i = 0 while i < length:  if search_name == names[i]:  search_name_index = i  break  i += 1 if i == length:  search_name_index = -1 #沒有找到的話令索引置為-1 print("the index of your search_name is:%d"%search_name_index) elif user_input_num == 5: #退出 print("quit success!") break else: print("input number wrong!/nplease input again")            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 赤水市| 佛学| 张家界市| 海口市| 玉龙| 汕头市| 福安市| 阿克陶县| 甘德县| 股票| 遂溪县| 滨州市| 桂阳县| 定西市| 定日县| 金平| 垫江县| 嘉黎县| 如东县| 孟连| 永嘉县| 怀来县| 思南县| 白朗县| 静宁县| 临朐县| 宝鸡市| 汉寿县| 沙雅县| 油尖旺区| 侯马市| 偏关县| 西盟| 隆回县| 龙游县| 邮箱| 西畴县| 穆棱市| 增城市| 沁阳市| 咸丰县|