-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodoapp.py
88 lines (72 loc) · 1.98 KB
/
todoapp.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
"""
ToDo App
This module implements a command-line to-do list application
for efficient task organization.
Author: Asibeh Tenager
Date: 01/07/2023
Usage:
- Run the script to start the ToDo app.
- Follow the on-screen instructions to manage your to-do lists and tasks.
Actions:
add - Add a new task to the ToDo list
delete - Delete a task from the ToDo list
list - List all tasks in the ToDo list
"""
tasks = []
def add_task():
"""
Add a new task to the to-do list.
"""
task = input("Enter a new task: ")
tasks.append(task)
print("Task added successfully.")
def view_tasks():
"""
View the tasks in the to-do list.
"""
if len(tasks) == 0:
print("no tasks.")
else:
print('List of tasks:')
for i, task in enumerate(tasks):
print(f'{i+1}. {task}')
def delete_task():
"""
Delete a task from the to-do list.
"""
if len(tasks) == 0:
print('no tasks to delete.')
else:
print('Tasks:')
for i, task in enumerate(tasks):
print(f'{i+1}. {task}')
choice = int(input('Enter the task number to delete:'))
if 0 < choice <= len(tasks):
del tasks[choice-1]
print('Task deleted successfully.')
else:
print('Invalid task number.')
def main():
"""
Run the command-line to-do list application.
"""
while True:
print('\n===== To-Do-List Application =====')
print("1. Add task")
print('2. view task')
print('3. Delete task')
print('4. Quit')
choice = int(input("Enter your choice:"))
if choice == 1:
add_task()
elif choice == 2:
view_tasks()
elif choice == 3:
delete_task()
elif choice == 4:
print("Thank you for using the To-Do-List Application.")
break
else:
print('Invalid choice. Please try again.')
if __name__ == "__main__":
main()