python编写日程管理工具
时间: 2023-10-17 21:24:54 浏览: 62
好的,下面是一个简单的 Python 日程管理工具的代码示例:
```python
import datetime
def add_event(events):
event = {}
event["name"] = input("请输入事件名称:")
event_date = input("请输入事件日期 (YYYY-MM-DD):")
year, month, day = map(int, event_date.split("-"))
event["date"] = datetime.date(year, month, day)
event["time"] = input("请输入事件时间 (HH:MM):")
events.append(event)
def view_events(events):
if len(events) == 0:
print("无事件")
else:
for event in events:
print(event["date"].strftime("%Y-%m-%d"), event["time"], event["name"])
def main():
events = []
while True:
print("请选择操作:")
print("1. 添加事件")
print("2. 查看事件")
print("3. 退出")
choice = input()
if choice == "1":
add_event(events)
elif choice == "2":
view_events(events)
elif choice == "3":
break
else:
print("无效操作,请重新输入")
if __name__ == "__main__":
main()
```
这个程序使用了 Python 的 datetime 模块来处理日期和时间。它可以添加新事件,查看已存在的事件,并且可以退出程序。你可以根据自己的需求对其进行修改和扩展,比如增加删除事件的功能、将事件保存到文件中等等。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)