-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.py
103 lines (44 loc) · 1.63 KB
/
project.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Initializing an empty task list
task_list = []
def main():
print("Welcome to Task Manager!")
while True:
print("\nMenu:")
print("1. Add Task")
print("2. List Tasks")
print("3. Complete Task")
print("4. Quit")
choice = input("Enter your choice: ")
if choice == "1":
task_description = input("Enter task description: ")
add_task(task_list, task_description)
elif choice == "2":
list_tasks(task_list)
elif choice == "3":
list_tasks(task_list)
task_index = int(input("Enter the index of the task to mark as completed: "))
complete_task(task_list, task_index)
elif choice == "4":
print("Goodbye!")
break
else:
print("Invalid choice. Please try again.")
def add_task(task_list, task_description):
task_list.append({"description": task_description, "completed": False})
print(f"Task '{task_description}' added successfully.")
def list_tasks(task_list):
if not task_list:
print("No tasks found.")
else:
print("Tasks:")
for i, task in enumerate(task_list):
status = "Completed" if task["completed"] else "Not Completed"
print(f"{i+1}. {task['description']} - {status}")
def complete_task(task_list, task_index):
if task_index >= 1 and task_index <= len(task_list):
task_list[task_index - 1]["completed"] = True
print("Task marked as completed.")
else:
print("Invalid task index.")
if __name__ == "__main__":
main()