1. Use a dictionary and list nesting structure to represent multiple records
2. When adding information, enter a word directly, parse and disassemble, and record time and event
3. Different color output with different information
#!/user/bin/env Python# _*_ coding:utf-8 _*_# 51memo.py# author:大宝dayday见__author__ = ‘大宝dayday见‘desc = ‘51备忘录‘.center(30,‘-‘)print(desc)welcome = ‘welcome‘print(f‘{welcome}作者:‘,__author__)# 添加备忘信息"""dict = {‘time‘:‘8点‘, ‘thing‘:‘起床‘ }"""all_memo = []is_add = Truewhile (is_add): one = {} info = input(‘请输入备忘信息:‘) one[‘时间‘] = info[info.find(‘点‘)-1:info.find(‘点‘)+1] one[‘事件‘] = info[info.find(‘点‘)+1:] all_memo.append(one) print(f‘备忘录{all_memo}‘) num = 0 for i in all_memo: num += 1 print(‘项目%s:%s‘ %(num,i)) print(f‘共{len(all_memo)}个待办事项‘,end=‘‘) is_add = input(‘是否继续 Y/N:‘) == ‘Y‘
------------51备忘录-------------welcome作者: 大宝dayday见请输入备忘信息:杰伦,今晚8点K歌备忘录[{‘时间‘: ‘8点‘, ‘事件‘: ‘K歌‘}]项目1:{‘时间‘: ‘8点‘, ‘事件‘: ‘K歌‘}共1个待办事项是否继续 Y/N:Y请输入备忘信息:圆圆,明天9点按时起床备忘录[{‘时间‘: ‘8点‘, ‘事件‘: ‘K歌‘}, {‘时间‘: ‘9点‘, ‘事件‘: ‘按时起床‘}]项目1:{‘时间‘: ‘8点‘, ‘事件‘: ‘K歌‘}项目2:{‘时间‘: ‘9点‘, ‘事件‘: ‘按时起床‘}共2个待办事项是否继续 Y/N:N print(‘\033[34;1m"我是蓝色"\033[0m‘) print(‘\033[32;1m"我是绿色"\033[0m‘) print(‘\033[33;1m"我是×××"\033[0m‘) print(‘\033[31;1m"我是红色"\033[0m‘)
Case: Python list nested dictionary implementation memo