File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
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 ("\n Options:" )
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." )
You can’t perform that action at this time.
0 commit comments