Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Commit 00877be

Browse files
Create task2.py and completed task2
1 parent f9d9e23 commit 00877be

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

‎ch_nandu/task2/task2.py‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
class TaskManager:
2+
def __init__(self):
3+
self.tasks = []
4+
5+
def add_task(self, task):
6+
self.tasks.append({"task": task, "completed": False})
7+
8+
def delete_task(self, index):
9+
if 0 <= index < len(self.tasks):
10+
del self.tasks[index]
11+
else:
12+
print("Invalid task index")
13+
14+
def mark_task_completed(self, index):
15+
if 0 <= index < len(self.tasks):
16+
self.tasks[index]["completed"] = True
17+
else:
18+
print("Invalid task index")
19+
20+
def display_tasks(self):
21+
print("Tasks:")
22+
for i, task in enumerate(self.tasks):
23+
status = "Completed" if task["completed"] else "Pending"
24+
print(f"{i+1}. {task['task']} - {status}")
25+
26+
27+
def main():
28+
task_manager = TaskManager()
29+
30+
while True:
31+
print("\nOptions:")
32+
print("1. Add Task")
33+
print("2. Delete Task")
34+
print("3. Mark Task as Completed")
35+
print("4. View Tasks")
36+
print("5. Exit")
37+
38+
choice = input("Enter your choice: ")
39+
40+
if choice == "1":
41+
task = input("Enter the task: ")
42+
task_manager.add_task(task)
43+
elif choice == "2":
44+
index = int(input("Enter the index of the task to delete: ")) - 1
45+
task_manager.delete_task(index)
46+
elif choice == "3":
47+
index = int(input("Enter the index of the task to mark as completed: ")) - 1
48+
task_manager.mark_task_completed(index)
49+
elif choice == "4":
50+
task_manager.display_tasks()
51+
elif choice == "5":
52+
print("Exiting...")
53+
break
54+
else:
55+
print("Invalid choice. Please try again.")
56+
57+
58+
if __name__ == "__main__":
59+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /