python编写一个简单的日程管理工具。包含添加日程,查询日程(按关键字查询),删除日程,查询日程列表(显示日程序号),编辑日程(按关键字显示原来的日程列表再编辑),退出程序的功能
时间: 2024-05-06 19:16:22 浏览: 11
好的,我可以帮您编写一个简单的日程管理工具。在这个工具中,我们将使用一个字典来存储所有的日程。在字典中,键是日程的编号,值是日程的内容。
以下是代码实现:
```python
schedule = {}
# 添加日程
def add_schedule():
schedule_id = input("请输入日程编号:")
schedule_text = input("请输入日程内容:")
schedule[schedule_id] = schedule_text
print("日程添加成功!")
# 查询日程
def search_schedule():
keyword = input("请输入关键字:")
for schedule_id, schedule_text in schedule.items():
if keyword in schedule_text:
print("编号:{},内容:{}".format(schedule_id, schedule_text))
# 删除日程
def delete_schedule():
schedule_id = input("请输入要删除的日程编号:")
if schedule_id in schedule:
del schedule[schedule_id]
print("日程删除成功!")
else:
print("日程不存在!")
# 查询日程列表
def list_schedule():
print("日程列表:")
for schedule_id in schedule:
print(schedule_id)
# 编辑日程
def edit_schedule():
keyword = input("请输入关键字:")
for schedule_id, schedule_text in schedule.items():
if keyword in schedule_text:
new_text = input("请输入新的日程内容:")
schedule[schedule_id] = new_text
print("日程修改成功!")
return
print("未找到符合条件的日程!")
# 主程序
while True:
print("请选择操作:")
print("1. 添加日程")
print("2. 查询日程")
print("3. 删除日程")
print("4. 查询日程列表")
print("5. 编辑日程")
print("6. 退出程序")
choice = input("请输入选项:")
if choice == "1":
add_schedule()
elif choice == "2":
search_schedule()
elif choice == "3":
delete_schedule()
elif choice == "4":
list_schedule()
elif choice == "5":
edit_schedule()
elif choice == "6":
break
else:
print("无效选项,请重新输入!")
```
在这个程序中,我们使用了一个 while 循环来不断接受用户的输入,并根据用户的选择来执行不同的操作。每个操作都对应一个函数,这些函数分别实现了添加、查询、删除、查询列表、编辑和退出功能。在这些函数中,我们使用了 input 函数来接受用户的输入,并使用 print 函数来输出结果。
请注意,这个程序只是一个简单的示例,可能还有很多需要改进的地方。例如,我们可以为每个日程添加更多的信息(如日期、时间等),或者使用数据库来存储日程信息。但是,这个程序已经足够演示如何使用 Python 来编写一个简单的日程管理工具了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)