溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么在python中利用面向?qū)ο髮崿F(xiàn)一個名片管理系統(tǒng)

發(fā)布時間:2021-04-20 16:27:46 來源:億速云 閱讀:223 作者:Leah 欄目:開發(fā)技術(shù)

怎么在python中利用面向?qū)ο髮崿F(xiàn)一個名片管理系統(tǒng)?相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

python可以做什么

Python是一種編程語言,內(nèi)置了許多有效的工具,Python幾乎無所不能,該語言通俗易懂、容易入門、功能強大,在許多領(lǐng)域中都有廣泛的應(yīng)用,例如最熱門的大數(shù)據(jù)分析,人工智能,Web開發(fā)等。

具體內(nèi)容如下

import os
def print_menu():
 print("*"*50)
 print("  名片管理系統(tǒng)")
 print("  1.添加一個新名片")
 print("  2.刪除一個名片信息")
 print("  3.修改一個名片信息")
 print("  4.查找一個名片信息")
 print("  5.顯示添加過的名片信息")
 print("  6.保存添加的名片信息")
 print("  7.退出系統(tǒng)")
 print("*"*50)
card_infor = []
def add_new_card_infor():
 new_name = input("請輸入要添加的名字:")
 new_qq = input("請輸入Qq:")
 new_weixin = input("請輸入微信號:")
 new_position = input("請輸入工作職位")
 new_addr = input("請輸入工作地址")
 """創(chuàng)建一個字典來存放添加的內(nèi)容"""
 new_infor = {}
 new_infor['name'] = new_name
 new_infor['qq'] = new_qq
 new_infor['weixin'] = new_weixin
 new_infor['position'] = new_position
 new_infor['addr'] = new_addr
 """將字典剛?cè)胍粋€列表中"""
 global card_infor
 card_infor.append(new_infor)
def del_card_infor():
 del_name =input("請輸入要刪除的名片")

 global card_infor
 for temp in card_infor:
  if del_name == temp['name']:
   print("刪除的名片如下")
   card_infor.remove(temp)
   print("%s\t\t%s\t\t%s\t\t%s\t\t%s"%(temp['name'],temp['qq'],temp['weixin'],temp['position'],temp['addr']))
  else:
   print("不存在")
   return del_card_infor()
def change_care_infor():
 change_name_card = input("請輸入需要修改的名片名字")
 global card_infor
 for temp in card_infor:
  if change_name_card == temp['name']:
   new_name = input("請輸入要修改的名字")
   new_qq = input("請輸入要修改的qq")
   new_weixin = input("請輸入要修改的微信")
   new_position = input("請輸入要修改的職業(yè)")
   new_addr = input("請輸入要修改的地址")
   temp['name'] = new_name
   temp['qq'] = new_qq
   temp['weixin'] = new_weixin
   temp['position'] = new_position
   temp['addr'] = new_addr
   print("修改成功")
   break
  else:
   print("您要修改的名片不存在")

def find_card_infor():
 global card_infor
 find_name = input("請輸入要在查找的內(nèi)容\n")
 find = 0
 for temp in card_infor:
  if find_name == temp['name']:
   print("查詢成功\n")
   print("%s\t\t%s\t\t%s\t\t%s\t\t%s"%(temp['name'],temp['qq'],temp['weixin'],temp['position'],temp['addr']))
   find = 1
   break
  else:
   print("您要查詢的名片不存在,請重新輸入")
   return find_card_infor()
def display_card_infor():
 global card_infor
 print("姓名\t\tQQ\t\t微信\t\t工作\t\t住址")
 for temp in card_infor:
  print("%s\t\t%s\t\t%s\t\t%s\t\t%s"%(temp['name'],temp['qq'],temp['weixin'],temp['position'],temp['addr']))
def save_card_infor():
 global card_infor
 f = open("save_card.data","w")
 f.write(str(card_infor))
 f.close()
def load_card_infor():
 """恢復(fù)保存的信息"""
 global card_infor
 try:
  f = open('save_card.data')
  card_infor = eval(f.read())
  f.close()
 except Exception:
  pass
def main():
 load_card_infor()
 """把恢復(fù)保存的信息加載到程序中"""
 print_menu()
 """加載首頁操作頁面"""
 while True:
  num = int(input("請輸入你要選擇的功能序號"))
  if(num==1):
   add_new_card_infor()
  elif(num==2):
   del_card_infor()
  elif(num==3):
   change_care_infor()
  elif(num==4):
   find_card_infor()
  elif(num==5):
   display_card_infor()
  elif(num==6):
   save_card_infor()
  elif(num==7):
   break
  else:
   print("輸入有誤,請重新輸入")
  print()
if __name__ == "__main__":
 main()

運行界面

怎么在python中利用面向?qū)ο髮崿F(xiàn)一個名片管理系統(tǒng)

怎么在python中利用面向?qū)ο髮崿F(xiàn)一個名片管理系統(tǒng)

看完上述內(nèi)容,你們掌握怎么在python中利用面向?qū)ο髮崿F(xiàn)一個名片管理系統(tǒng)的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI