-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday 5.py
More file actions
80 lines (57 loc) · 1.64 KB
/
day 5.py
File metadata and controls
80 lines (57 loc) · 1.64 KB
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
todo_app = "file.txt"
def add_task():
task = input("Enter task: ")
if task == "":
print("Task can't be empty ❌")
return
with open(todo_app, "a") as file:
file.write(task + "\n")
print("Task added successfully ✅")
def view_task():
try:
with open(todo_app, "r") as file:
tasks = file.readlines()
if len(tasks) == 0:
print("No task found 📭")
return
print("\n--- Your Tasks ---")
for i, task in enumerate(tasks, start=1):
print(f"{i}. {task.strip()}")
except FileNotFoundError:
print("No tasks yet 📭")
def delete_task():
try:
with open(todo_app, "r") as file:
tasks = file.readlines()
if len(tasks) == 0:
print("No task found ❌")
return
view_task()
num = int(input("Enter task number: "))
if num < 1 or num > len(tasks):
print("Invalid task number ❌")
return
tasks.pop(num - 1)
with open(todo_app, "w") as file:
file.writelines(tasks)
print("Task deleted successfully 🗑️")
except FileNotFoundError:
print("No task found ❌")
while True:
print("\n=== TO-DO APP ===")
print("1. Add Task")
print("2. View Tasks")
print("3. Delete Task")
print("4. Exit")
choice = input("Enter choice: ")
if choice == "1":
add_task()
elif choice == "2":
view_task()
elif choice == "3":
delete_task()
elif choice == "4":
print("Goodbye 👋")
break
else:
print("Invalid choice ❌")