-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
70 lines (60 loc) · 2.18 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class Task:
def __init__(self, description):
self.description = description
self.completed = False
class TaskManager:
def __init__(self):
self.tasks = []
def add_task(self, description):
task = Task(description)
self.tasks.append(task)
def view_tasks(self):
if not self.tasks:
print("No tasks available.")
else:
print("Tasks:")
for index, task in enumerate(self.tasks, start=1):
status = "Completed" if task.completed else "Pending"
print(f"{index}. {task.description} - {status}")
def mark_task_completed(self, task_index):
if 1 <= task_index <= len(self.tasks):
self.tasks[task_index - 1].completed = True
print("Task marked as completed...")
else:
print("Invalid task index.")
def write_tasks(self):
"""
This method writes the list of tasks to a file
"""
with open('output.txt', 'w') as file:
for index, task in enumerate(self.tasks, start=1):
status = "Completed" if task.completed else "Pending"
file.write(f"{index}. {task.description} - {status}\n")
def main():
task_manager = TaskManager()
while True:
print("\nTask Management System")
print("1. Add Task")
print("2. View Tasks")
print("3. Mark Task as Completed")
print("4. Exit")
print("5. Export tasks as file")
choice = input("Enter your choice: ")
if choice == "1":
description = input("Enter task description: ")
task_manager.add_task(description)
print("Task added successfully.")
elif choice == "2":
task_manager.view_tasks()
elif choice == "3":
task_index = int(input("Enter task index to mark as completed: "))
task_manager.mark_task_completed(task_index)
elif choice == "4":
print("Exiting program.")
break
elif choice == "5":
task_manager.write_tasks()
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()