代码:class Todolist:
n = []
u = []
def list(self):
print('紧急:')
for i in self.u:
print(i)
print()
print('普通:')
for i in self.n:
print(i)
def add(self,t,s):
if t:
self.u.insert(0,s)
else:
self.n.insert(0,s)
def delete(self,t,s):
if t:
self.u.remove(s)
else:
self.n.remove(s)
def main():
t = Todolist()
while 1:
command = input('请输入命令:')
if command == 'list':
t.list()
elif command == 'add':
t2 = int(input('请输入事件类型(1 -->紧急,0 -->普通)'))
if t2 > 1 or t2 < 0:
print('没有此类型!!!')
continue
else:
s = input('请输入事件:')
if s in t.n or s in t.u:
print('此事件已存在,请先用delete删除!!!')
continue
t.add(t2,s)
elif command == 'delete':
t2 = int(input('请输入事件类型(1 -->紧急,0 -->普通)'))
if t2 > 1 or t2 < 0:
print('没有此类型!!!')
continue
else:
s = input('请输入事件:')
if not s in t.n or s in t.u:
print('此事件不存在,请先用add添加!!!')
continue
t.delete(t2,s)
elif command == 'exit':
break
else:
print('不存在此命令!!!')
print('*' * 50)
if __name__ == '__main__':
main()
|