Python使用字典实现的简单记事本功能示例
本文实例讲述了Python使用字典实现的简单记事本功能。分享给大家供大家参考,具体如下:
fromtimeimportsleep,strftime
user="Cytus"
calendar={}
defwelcome():
print"Welcometousethiscalendar.%s"%user
print"Calendarisopening."
sleep(1)
printstrftime("%A%B%d%Y")
printstrftime("%H:%M:%S")
sleep(1)
print"Whatwouldyouliketodo?"
defstart_calendar():
welcome()
start=True
whilestart:
user_choice=raw_input("Atoadd,UtoUpdate,VtoView,DtoDelete,XtoExit:")
user_choice=user_choice.upper()
ifuser_choice=="V":
iflen(calendar.keys())<1:
print"Thecalendarisempty."
else:
printcalendar
elifuser_choice=="U":
date=raw_input("Whatdate?")
update=raw_input("Entertheupdate:")
calendar[date]=update
print"Updatesuccessful."
printcalendar
elifuser_choice=="A":
event=raw_input("Enterevent:")
date=raw_input("Enterdate(MM/DD/YYYY):")
if(len(date)>10)orint(date[6:])
运行结果:
>>>
Welcometousethiscalendar.Cytus
Calendarisopening.
ThursdayAugust152019
11:25:13
Whatwouldyouliketodo?
Atoadd,UtoUpdate,VtoView,DtoDelete,XtoExit:A
Enterevent:www.nhooo.com
Enterdate(MM/DD/YYYY):08/15/2019
Successfullyadded.
{'08/15/2019':'www.nhooo.com'}
Atoadd,UtoUpdate,VtoView,DtoDelete,XtoExit:V
{'08/15/2019':'www.nhooo.com'}
Atoadd,UtoUpdate,VtoView,DtoDelete,XtoExit:
Atoadd,UtoUpdate,VtoView,DtoDelete,XtoExit:X
>>>
更多关于Python相关内容感兴趣的读者可查看本站专题:《Python字典操作技巧汇总》、《Python列表(list)操作技巧总结》、《Python函数使用技巧总结》、《Python数据结构与算法教程》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程》
希望本文所述对大家Python程序设计有所帮助。
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短