Python使用字典實(shí)現(xiàn)的簡(jiǎ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: www.dbjr.com.cn
Enter date (MM/DD/YYYY): 08/15/2019
Successfully added.
{'08/15/2019': 'www.dbjr.com.cn'}
A to add, U to Update, V to View, D to Delete, X to Exit: V
{'08/15/2019': 'www.dbjr.com.cn'}
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入門(mén)與進(jìn)階經(jīng)典教程》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
手把手教你jupyter?notebook更換環(huán)境的方法
在日常使用jupyter-notebook時(shí),可能會(huì)碰到需要切換不同虛擬環(huán)境的場(chǎng)景,下面這篇文章主要給大家介紹了關(guān)于jupyter?notebook更換環(huán)境的方法,需要的朋友可以參考下2023-05-05使用python 將圖片復(fù)制到系統(tǒng)剪貼中
今天小編就為大家分享一篇使用python 將圖片復(fù)制到系統(tǒng)剪貼中,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12Python語(yǔ)言描述機(jī)器學(xué)習(xí)之Logistic回歸算法
這篇文章主要介紹了Python語(yǔ)言描述機(jī)器學(xué)習(xí)之Logistic回歸算法,涉及Sigmoid函數(shù),梯度上升法等相關(guān)內(nèi)容,具有一定借鑒價(jià)值,需要的朋友可以參考下。2017-12-12Python使用Pickle庫(kù)實(shí)現(xiàn)讀寫(xiě)序列操作示例
這篇文章主要介紹了Python使用Pickle庫(kù)實(shí)現(xiàn)讀寫(xiě)序列操作,結(jié)合實(shí)例形式分析了pickle模塊的功能、常用函數(shù)以及序列化與反序列化相關(guān)操作技巧,需要的朋友可以參考下2018-06-06Python實(shí)現(xiàn)Event回調(diào)機(jī)制的方法
今天小編就為大家分享一篇Python實(shí)現(xiàn)Event回調(diào)機(jī)制的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-02-02python實(shí)現(xiàn)定時(shí)發(fā)送qq消息
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)定時(shí)發(fā)送qq消息,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01Django JWT Token RestfulAPI用戶認(rèn)證詳解
這篇文章主要介紹了Django JWT Token RestfulAPI用戶認(rèn)證詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-01-01