-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.To Do List .py
92 lines (76 loc) · 2.73 KB
/
1.To Do List .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
# TASK-1-CODSOFT
'''
A To-Do List application is a useful project that helps users manage
and organize their tasks efficiently. This project aims to create a
command-line or GUI-based application using Python, allowing
users to create, update, and track their to-do lists
'''
# Function for displaying the Tasks
def display_menu():
print("\nTo-Do List Application")
print("1. Add Task")
print("2. List Tasks")
print("3. Update Task")
print("4. Mark Task as Done")
print("5. Exit")
# Funnction for the input of task from User
def add_task(tasks):
task = input("Enter the task: ")
tasks.append({"task": task, "done": False})
print(f'Task "{task}" added.')
# Function for Displaying the Overall Tasks
def list_tasks(tasks):
if not tasks:
print("No tasks available.")
else:
for i, task in enumerate(tasks, start=1):
status = "Done" if task["done"] else "Pending"
print(f"{i}. {task['task']} - {status}")
# Function for the updation of existing tasks
def update_task(tasks):
list_tasks(tasks)
if tasks:
try:
task_number = int(input("Enter the task number to update: ")) - 1
if 0 <= task_number < len(tasks):
new_task = input("Enter the new task description: ")
tasks[task_number]["task"] = new_task
print(f'Task {task_number + 1} updated to "{new_task}".')
else:
print("Invalid task number.")
except ValueError:
print("Please enter a valid number.")
# Function for marking the Tasks which are done
def mark_task_done(tasks):
list_tasks(tasks)
if tasks:
try:
task_number = int(input("Enter the task number to mark as done: ")) - 1
if 0 <= task_number < len(tasks):
tasks[task_number]["done"] = True
print(f'Task "{tasks[task_number]["task"]}" marked as done.')
else:
print("Invalid task number.")
except ValueError:
print("Please enter a valid number.")
# Todo Fn for Selecting the choice of user
def Todo():
tasks = []
while True:
display_menu()
choice = input("Choose an option: ")
if choice == '1':
add_task(tasks)
elif choice == '2':
list_tasks(tasks)
elif choice == '3':
update_task(tasks)
elif choice == '4':
mark_task_done(tasks)
elif choice == '5':
print("Exiting the application. Goodbye!")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
Todo()