Python 列表字典製作名冊管理

來源:互聯網
上載者:User

標籤:name   weixin   glob   序號   列表   rs.remove   input   col   函數   

  1 #用來儲存名片的列表  2 card_infors = []  3   4   5   6 def print_menu():  7     #1. 列印功能提示  8     print("="*50)  9     print(" 名片管理系統") 10     print("1. 增加一個新名片") 11     print("2. 刪除一個名稱") 12     print("3. 修改一個名片") 13     print("4. 查詢一個名片") 14     print("5. 顯示所有名片") 15     print("6. 退出系統") 16     print("="*50) 17  18  19 def add_new_card_infor(): 20         """完成文檔輸入:""" 21         new_name = input("請輸入新的名字:") 22         new_qq = input("請輸入新的QQ:") 23         new_weixin = input("請輸入新的:") 24         new_addr = input("請輸入地址:") 25  26         # 定義一個新的字典,用來儲存新的名片 27         new_infor = {} 28         new_infor[‘name‘] = new_name 29         new_infor[‘qq‘] = new_qq 30         new_infor["weixin"] = new_weixin 31         new_infor[‘addr‘] = new_addr 32         global card_infors 33         card_infors.append(new_infor) 34  35  36 def find_card_infor(): 37         find_name = input("請輸入要尋找的姓名:") 38  39         find_flag = 0   # 預設沒有找到 40  41         global card_infors 42         for temp in card_infors: 43             if find_name == temp["name"]: 44                print("%s\t%s\t%s\t%s"%(temp[‘name‘],temp[‘qq‘],temp[‘weixin‘],temp[‘addr‘])) 45                find_flag=1 46                break 47         if find_flag == 0: 48             print("查無此人") 49  50 def show_all_infor(): 51         """顯示所有資訊""" 52         print("姓名\tQQ\t\t住址") 53         global card_infors 54         for temp in card_infors: 55             # print(temp) 56             print("%s\t%s\t%s\t%s"%(temp[‘name‘],temp[‘qq‘],temp[‘weixin‘],temp[‘addr‘])) 57  58  59 def del_card_infor(): 60         del_name = input("請輸入要尋找的姓名:") 61         find_flag = 0   # 預設沒找到 62          63         global card_infors 64         for temp in card_infors: 65             if del_name == temp["name"]: 66                 card_infors.remove(temp) 67                 find_flag = 1 68                 show_all_infor() 69                 break 70         if find_flag == 0: 71             print("查無此人") 72                  73  74 def del_modify_infor(): 75         modify_name = input("請輸入要修改資訊的名稱:") 76         find_flag = 0 77  78         global card_infors 79         for temp in card_infors: 80             if modify_name == temp["name"]: 81                 modify_content = input("請輸入要修改的資訊,如name,qq,weixin,addr等:") 82                 for name in temp.keys(): 83                     print("+"*50) 84                     print(temp.keys()) 85                     print("+"*50) 86                     print(name) 87                     if modify_content == name: 88                         modify_value = input("請輸入要修改的值:") 89                         temp[name] = modify_value 90                         show_all_infor() 91                         find_flag = 1 92                         break 93                      94         if find_flag == 0: 95             print("查無此人")           96  97  98  99 100 def main():101         """完成對整個程式得控制"""102     103         print_menu()104         while True:105             #2. 擷取使用者的輸入106             num = int(input("請輸入操作序號:"))107 108             #3. 根據使用者的資料執行相應的功能:109             if num == 1:110                 add_new_card_infor()111             elif num == 2:112                 del_card_infor()113             elif num == 3:114                 del_modify_infor()115             elif num == 4:116                 find_card_infor()117             elif num == 5:118                 show_all_infor()119             elif num == 6:120                 break121             else:122                 print("輸入有誤,請重新輸入:")123  124 125 126 # 調用主函數127 main()

 

Python 列表字典製作名冊管理

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.