日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python:用字典建立一个通讯录,向字典中添加和删除通讯人信息,查询某个人的信息,然后输出通讯录中所有人的信息。

發布時間:2025/3/20 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python:用字典建立一个通讯录,向字典中添加和删除通讯人信息,查询某个人的信息,然后输出通讯录中所有人的信息。 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

用字典建立一個通訊錄,向字典中添加和刪除通訊人(名字、電話、郵箱、工作單位等),查詢某個人的信息,然后輸出通訊錄中所有人的信息。

采用列表里套字典的方法,比較簡單

contacts = []def add():mes = "Please enter the message of the people,and spilt them with space"mes +="\nphone email adress "name = input("Please enter the name of the people:\n")#定義提示信息,收集名字進行下一步的判斷if name in contacts:print(f"{name.title()} is insist,whether change the people's information,")com =("Please enter 'yes' or 'no'")#如果已經收錄此人信息,反饋以獲得下一步的行動email = 'NONE'adress = 'NONE'if com == 'yes':contact.remove(name)#將原信息刪除try:phone,email,address = input(mes).split()contacts.append({'name' : name , 'phone' : phone , 'email' : email,'address':address})except ValueError:print("The message is not enough")#收集三個信息,并且在信息不足時反饋給用戶else:try:phone,email,address = input(mes).split()contacts.append({'name' : name , 'phone' : phone , 'email' : email,'address':address})except ValueError:print("The message is not enough")#在此用戶不存在時進行正常流程def lookfor(name):for i in contacts:if i['name'] == name:return ielse:print("The people doesn't in your contacts")#定義查找函數,返回需要查找的聯系人的字典def delect():name = input("Please input the name you want to delect")contacts.remove(lookfor(name))#進行刪除聯系人def inquire():name = input("Please enter the name you want to inquire")print(lookfor(name))#輸出查找聯系人的信息def outputall():for i in contacts:print(i) #輸出全部信息 while True:comand = "\nYou can enter different command to realize different functions,\n"comand +="1 . add liaisons;\n2 . delect liaisons; \n3 .inquire liaisons ; \n"comand +="4.out put all over information.\nYou can enter 'q' at any time to quit"print(comand)#給予操作提示cmd = input("Please enter the command you want to realize:\n")#收集操作指令if cmd == '1':add()elif cmd == '2':delect()elif cmd == '3':inquire()elif cmd == '4':outputall()elif cmd == '5':breakelse:print("\nThe command is not allowed") #分別進行不同的操作

總結

以上是生活随笔為你收集整理的Python:用字典建立一个通讯录,向字典中添加和删除通讯人信息,查询某个人的信息,然后输出通讯录中所有人的信息。的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。