Skip to content

Commit f444ded

Browse files
Megh-Ranatechyminati
authored andcommitted
python_codes: add script to manage daily tasks
Options: 1. Add a task 2. View tasks 3. Delete a task 4. Quit
1 parent 9405b04 commit f444ded

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Hacktober2023/tasks.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Initialize an empty list to store tasks
2+
tasks = []
3+
4+
# Function to add a task to the list
5+
def add_task(task):
6+
tasks.append(task)
7+
print("Task added: ", task)
8+
9+
# Function to view all tasks in the list
10+
def view_tasks():
11+
if tasks:
12+
print("Tasks:")
13+
for i, task in enumerate(tasks, 1):
14+
print(f"{i}. {task}")
15+
else:
16+
print("No tasks to display.")
17+
18+
# Function to delete a task from the list
19+
def delete_task(task_number):
20+
if task_number > 0 and task_number <= len(tasks):
21+
deleted_task = tasks.pop(task_number - 1)
22+
print("Deleted task:", deleted_task)
23+
else:
24+
print("Invalid task number.")
25+
26+
# Main loop
27+
while True:
28+
print("\nOptions:")
29+
print("1. Add a task")
30+
print("2. View tasks")
31+
print("3. Delete a task")
32+
print("4. Quit")
33+
34+
choice = input("Enter your choice: ")
35+
36+
if choice == '1':
37+
task = input("Enter the task: ")
38+
add_task(task)
39+
elif choice == '2':
40+
view_tasks()
41+
elif choice == '3':
42+
task_number = int(input("Enter the task number to delete: "))
43+
delete_task(task_number)
44+
elif choice == '4':
45+
print("Goodbye!")
46+
break
47+
else:
48+
print("Invalid choice. Please try again.")

0 commit comments

Comments
 (0)