请用python写一个日程管理程序
时间: 2023-07-01 22:23:45 浏览: 96
一个自己写的日程管理软件
好的,下面是一个简单的日程管理程序的Python代码示例:
```
import datetime
class Event:
def __init__(self, name, date, time, description):
self.name = name
self.date = date
self.time = time
self.description = description
class Schedule:
def __init__(self):
self.events = []
def add_event(self, event):
self.events.append(event)
def delete_event(self, event):
self.events.remove(event)
def view_events(self):
for event in self.events:
print("Name:", event.name)
print("Date:", event.date)
print("Time:", event.time)
print("Description:", event.description)
print()
schedule = Schedule()
while True:
print("1. Add event")
print("2. Delete event")
print("3. View events")
print("4. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
name = input("Enter event name: ")
date = input("Enter event date (YYYY-MM-DD): ")
time = input("Enter event time (HH:MM): ")
description = input("Enter event description: ")
event = Event(name, date, time, description)
schedule.add_event(event)
print("Event added successfully!")
elif choice == 2:
name = input("Enter event name to delete: ")
for event in schedule.events:
if event.name == name:
schedule.delete_event(event)
print("Event deleted successfully!")
break
else:
print("Event not found!")
elif choice == 3:
if len(schedule.events) == 0:
print("No events found!")
else:
schedule.view_events()
elif choice == 4:
break
else:
print("Invalid choice, please try again!")
```
这个程序使用Event类来表示一个事件,包含名称、日期、时间和描述。Schedule类包含一个事件列表,并提供了添加、删除和查看事件的方法。主循环允许用户选择要执行的操作,直到选择退出。
阅读全文