python编写一个简单的日程管理工具包含日程添加,查询日程(按关键字查询),删除日程,显示日程列表(要显示日程序号),编辑日程(显示原来的日程列表再编辑),退出程序的功能
时间: 2024-04-30 15:21:18 浏览: 132
好的,我可以为您提供 Python 代码示例,实现您所需的日程管理工具。以下是一个简单的实现:
```python
# 定义日程管理器类
class ScheduleManager:
def __init__(self):
self.schedules = [] # 创建一个空的日程列表
# 添加日程
def add_schedule(self, schedule):
self.schedules.append(schedule)
# 查询日程
def search_schedule(self, keyword):
results = []
for i, schedule in enumerate(self.schedules):
if keyword in schedule:
results.append((i, schedule))
return results
# 删除日程
def delete_schedule(self, index):
if 0 <= index < len(self.schedules):
del self.schedules[index]
# 显示日程列表
def show_schedules(self):
for i, schedule in enumerate(self.schedules):
print(f"{i+1}. {schedule}")
# 编辑日程
def edit_schedule(self, index, new_schedule):
if 0 <= index < len(self.schedules):
self.schedules[index] = new_schedule
# 创建日程管理器对象
manager = ScheduleManager()
# 定义主程序函数
def main():
while True:
print("请选择操作:")
print("1. 添加日程")
print("2. 查询日程")
print("3. 删除日程")
print("4. 显示日程列表")
print("5. 编辑日程")
print("6. 退出程序")
choice = input("请输入操作编号:")
if choice == "1":
schedule = input("请输入日程:")
manager.add_schedule(schedule)
print("添加成功!")
elif choice == "2":
keyword = input("请输入查询关键字:")
results = manager.search_schedule(keyword)
if len(results) == 0:
print("未找到符合条件的日程!")
else:
for i, result in results:
print(f"{i+1}. {result}")
elif choice == "3":
index = int(input("请输入要删除的日程编号:")) - 1
manager.delete_schedule(index)
print("删除成功!")
elif choice == "4":
manager.show_schedules()
elif choice == "5":
index = int(input("请输入要编辑的日程编号:")) - 1
old_schedule = manager.schedules[index]
new_schedule = input(f"原日程为 {old_schedule},请输入新日程:")
manager.edit_schedule(index, new_schedule)
print("编辑成功!")
elif choice == "6":
print("感谢使用日程管理工具,再见!")
break
else:
print("无效的操作编号,请重新输入!")
if __name__ == "__main__":
main()
```
这个程序中创建了一个日程管理器类 `ScheduleManager`,包含了添加、查询、删除、显示、编辑日程等功能。主程序函数 `main` 中提供了一个简单的控制台界面,让用户可以使用这些功能来管理自己的日程。您可以根据需要修改代码,以适应您的实际场景。
阅读全文
相关推荐

















