Skip to content

Commit 6eb9a0c

Browse files
committed
task2 ToDo list completed
1 parent b5be041 commit 6eb9a0c

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#todo class
2+
class ToDo:
3+
#main task list initialization
4+
def __init__(self):
5+
self.tasks = []
6+
7+
def new_task(self,task):
8+
'''
9+
Adds new task to the list
10+
param task: task to be added
11+
'''
12+
self.tasks.append(task)
13+
print("Task added sucessfully")
14+
print("")
15+
16+
def del_task(self,task_index):
17+
'''
18+
Deletes task from the list by index
19+
param task_index: index of task to be deleted
20+
'''
21+
self.tasks.pop(task_index - 1)
22+
print("Task deleted successfully")
23+
print("")
24+
25+
26+
def mrk_task(self,task_index):
27+
'''
28+
Marks task from the list as completed by index
29+
param task_index: index of task to be marked as completed
30+
'''
31+
task = self.tasks[task_index - 1]
32+
self.tasks[task_index - 1] = task + ' - completed'
33+
print("Yey ! task completed")
34+
print("")
35+
36+
#prints tasks
37+
def prt_task(self):
38+
for task in self.tasks:
39+
index = self.tasks.index(task) + 1
40+
print("{}.{}".format(index,task))
41+
print(" ")
42+
43+
#main method
44+
def main():
45+
todo = ToDo()
46+
choice = 1
47+
while True:
48+
choice = int(input("Select option \n 1. Add new task \n 2. Delete task \n 3. Mark task as completed \n 4. Print tasks\n 5. Exit \nEnter Number : "))
49+
if(choice == 1):
50+
task = input("Enter new task : ")
51+
todo.new_task(task)
52+
elif(choice == 2):
53+
task_index = int(input("Enter task index to delete(get it via printing tasks) : "))
54+
todo.del_task(task_index)
55+
elif(choice == 3):
56+
task_index = int(input("Enter task index to mark completed (get it via printing tasks) : "))
57+
todo.mrk_task(task_index)
58+
elif(choice == 4):
59+
todo.prt_task()
60+
elif(choice == 5):
61+
exit(0) #exit condition
62+
else:
63+
print("Wrong choice !")
64+
65+
if __name__ == '__main__':
66+
main()

0 commit comments

Comments
 (0)