最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python使用字典實(shí)現(xiàn)的簡(jiǎn)單記事本功能示例

 更新時(shí)間:2019年08月15日 11:31:57   作者:Cytues  
這篇文章主要介紹了Python使用字典實(shí)現(xiàn)的簡(jiǎn)單記事本功能,結(jié)合實(shí)例形式分析了基于字典的數(shù)據(jù)存儲(chǔ)、讀取、刪除等相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Python使用字典實(shí)現(xiàn)的簡(jiǎn)單記事本功能。分享給大家供大家參考,具體如下:

from time import sleep, strftime
user = "Cytus"
calendar = {}
def welcome():
  print "Welcome to use this calendar. %s" % user
  print "Calendar is opening."
  sleep(1)
  print strftime("%A %B %d %Y")
  print strftime("%H:%M:%S")
  sleep(1)
  print "What would you like to do?"
def start_calendar():
  welcome()
  start = True
  while start:
    user_choice = raw_input("A to add, U to Update, V to View, D to Delete, X to Exit: ")
    user_choice = user_choice.upper()
    if user_choice == "V":
      if len(calendar.keys()) < 1:
        print "The calendar is empty."
      else:
        print calendar
    elif user_choice == "U":
      date = raw_input("What date? ")
      update = raw_input("Enter the update: ")
      calendar[date] = update
      print "Update successful."
      print calendar
    elif user_choice == "A":
      event = raw_input("Enter event: ")
      date = raw_input("Enter date (MM/DD/YYYY): ")
      if (len(date) > 10) or int(date[6:]) < int(strftime("%Y")):
        print "invaild date."
        try_again = raw_input("Try again? Y for yes, N for No: ")
        try_again = try_again.upper()
        if try_again == "Y":
          continue
        else:
          start = False
      else:
        calendar[date] = event
        print "Successfully added."
        print calendar
    elif user_choice == "D":
      if len(calendar.keys()) < 1:
        print "The calendar is empty."
      else:
        event = raw_input("What event? ")
        for date in calendar.keys():
          if calendar[date] == event:
            del calendar[date]
            print "Delete successfully."
            print calendar
          else:
            print "incorrect event was specified."
    elif user_choice == "X":
      start = False
    else:
      print "invalid input."
      start = False
start_calendar()

運(yùn)行結(jié)果:

>>>
Welcome to use this calendar. Cytus
Calendar is opening.
Thursday August 15 2019
11:25:13
What would you like to do?
A to add, U to Update, V to View, D to Delete, X to Exit: A
Enter event: m.fzitv.net
Enter date (MM/DD/YYYY): 08/15/2019
Successfully added.
{'08/15/2019': 'm.fzitv.net'}
A to add, U to Update, V to View, D to Delete, X to Exit: V
{'08/15/2019': 'm.fzitv.net'}
A to add, U to Update, V to View, D to Delete, X to Exit:
A to add, U to Update, V to View, D to Delete, X to Exit: X
>>>

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python字典操作技巧匯總》、《Python列表(list)操作技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • 使用Python實(shí)現(xiàn)FTP文件自動(dòng)傳輸腳本

    使用Python實(shí)現(xiàn)FTP文件自動(dòng)傳輸腳本

    這篇文章主要為大家詳細(xì)介紹了如何使用Python實(shí)現(xiàn)FTP文件自動(dòng)傳輸腳本,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以了解下
    2023-12-12
  • Python自動(dòng)創(chuàng)建Excel并獲取內(nèi)容

    Python自動(dòng)創(chuàng)建Excel并獲取內(nèi)容

    這篇文章主要介紹了Python自動(dòng)創(chuàng)建Excel并獲取內(nèi)容,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • 用Python做一個(gè)嗶站小姐姐詞云跳舞視頻

    用Python做一個(gè)嗶站小姐姐詞云跳舞視頻

    這篇文章主要介紹了用Python做一個(gè)嗶站小姐姐詞云跳舞視頻, 本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-08-08
  • Python內(nèi)建函數(shù)之raw_input()與input()代碼解析

    Python內(nèi)建函數(shù)之raw_input()與input()代碼解析

    這篇文章主要介紹了Python內(nèi)建函數(shù)之raw_input()與input()代碼解析,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-10-10
  • GPU狀態(tài)監(jiān)測(cè)?nvidia-smi?命令的用法詳解

    GPU狀態(tài)監(jiān)測(cè)?nvidia-smi?命令的用法詳解

    這篇文章主要介紹了GPU狀態(tài)監(jiān)測(cè)?nvidia-smi?命令的用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • python發(fā)qq消息轟炸虐狗好友思路詳解(完整代碼)

    python發(fā)qq消息轟炸虐狗好友思路詳解(完整代碼)

    因?yàn)槲业哪硞€(gè)好友在情人節(jié)的時(shí)候秀恩愛,所以我靈光一閃制作了qq消息轟炸并記錄了下來。本文給大家分享python發(fā)qq消息轟炸虐狗好友思路詳解,感興趣的朋友一起看看吧
    2020-02-02
  • python 處理string到hex腳本的方法

    python 處理string到hex腳本的方法

    今天小編就為大家分享一篇python 處理string到hex腳本的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-10-10
  • Jupyter Notebook讀入csv文件時(shí)出錯(cuò)的解決方案

    Jupyter Notebook讀入csv文件時(shí)出錯(cuò)的解決方案

    這篇文章主要介紹了Jupyter Notebook讀入csv文件時(shí)出錯(cuò)的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • Python緩存利器之cachetools庫(kù)使用詳解

    Python緩存利器之cachetools庫(kù)使用詳解

    cachetools庫(kù)為Python提供了強(qiáng)大而靈活的緩存解決方案,通過使用不同類型的緩存和緩存裝飾器,我們可以輕松地在程序中實(shí)現(xiàn)高效的緩存機(jī)制,從而提升程序性能,本文將詳細(xì)介紹cachetools庫(kù)的基本概念和使用方法,感興趣的朋友跟隨小編一起看看吧
    2024-07-07
  • python編碼最佳實(shí)踐之總結(jié)

    python編碼最佳實(shí)踐之總結(jié)

    python編碼最佳實(shí)踐之總結(jié),幫助大家整理了python編碼最佳實(shí)踐的相關(guān)知識(shí)點(diǎn),重點(diǎn)從性能角度出發(fā)對(duì)python的一些慣用法做一個(gè)簡(jiǎn)單總結(jié),感興趣的小伙伴們可以參考一下
    2016-02-02

最新評(píng)論

慈利县| 馆陶县| 云霄县| 德令哈市| 临沂市| 姜堰市| 东乌珠穆沁旗| 扬中市| 阿合奇县| 邓州市| 德保县| 孟连| 象山县| 中方县| 会东县| 洛南县| 印江| 土默特左旗| 文山县| 清河县| 迁西县| 静乐县| 东光县| 涿鹿县| 涟水县| 枣强县| 贵定县| 安化县| 长治县| 苍梧县| 屏山县| 西林县| 泰州市| 平利县| 镇远县| 尼木县| 湄潭县| 马尔康县| 江山市| 大洼县| 渭南市|