Skip to content

Commit 94fcd3d

Browse files
authored
Create todolist.py
1 parent b6adc71 commit 94fcd3d

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

TODO (CLI-VER)/todolist.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#Check for the existence of file
2+
no_of_items=0
3+
try:
4+
f=open("todolist.txt")
5+
p=0
6+
for i in f.readlines():#Counting the number of items if the file exists already
7+
p+=1
8+
no_of_items=p-2
9+
except:
10+
f=open("todolist.txt",'w')
11+
f.write("_________TODO LIST__________\n")
12+
f.write(" TIME WORK")
13+
finally:
14+
f.close()
15+
#Todo list
16+
17+
print("Press 1: Add Item \nPress 2: Delete Item \nPress 3: Update item \nPress 4: Display Items\nPress 5: Exit")
18+
n=int(input())
19+
20+
21+
while n==1 or n==2 or n==3 or n==4:
22+
if n==1:
23+
todo=[]
24+
print("Enter the time in HH:MM format(24 hours format)")
25+
time=input()
26+
print("Enter your Work")
27+
work=input()
28+
no_of_items+=1
29+
with open('todolist.txt','a') as f:
30+
f.write("\n"+str(no_of_items)+" "+time+" "+work)
31+
elif n==2:
32+
if(no_of_items<=0):
33+
print("There is no item in the list kindly add some items")
34+
else:
35+
print("____________________________________________________________")
36+
print("Your Current List: ")
37+
todo=[]
38+
with open('todolist.txt') as f:
39+
for i in f.readlines():
40+
print(i)
41+
todo.append(i)
42+
print("____________________________________________________________")
43+
print("Enter the position of the item you want to delete : ")
44+
pos=int(input())
45+
if(pos<=0):
46+
print("Please enter a valid position")
47+
elif (pos>(no_of_items)):
48+
print("Please enter the position <= {}".format(no_of_items))
49+
else:
50+
51+
todo.pop(pos+1)
52+
53+
no_of_items-=1
54+
if(no_of_items<=0):
55+
print("Congratulations your todo list is empty!")
56+
57+
with open('todolist.txt','w') as f:
58+
for i in range(len(todo)):
59+
if i>=(pos+1):
60+
f.write(str(pos)+todo[i][1:])
61+
pos+=1
62+
else:
63+
f.write(todo[i])
64+
65+
elif n==3:
66+
print("____________________________________________________________")
67+
print("Your Current List: ")
68+
todo=[]
69+
with open('todolist.txt') as f:
70+
for i in f.readlines():
71+
print(i)
72+
todo.append(i)
73+
print("____________________________________________________________")
74+
print("Enter the position of the items you want to update : ")
75+
pos=int(input())
76+
if(pos<=0):
77+
print("Please enter a valid position")
78+
elif (pos>(no_of_items)):
79+
print("Please enter the position <= {}".format(no_of_items))
80+
else:
81+
print("What you want to update : ")
82+
print("Press 1: Time\nPress 2: Work")
83+
choice=int(input())
84+
if choice==1:
85+
print("Enter your updated time :")
86+
time=input()
87+
p=todo[pos+1].index(":")
88+
y=0
89+
with open('todolist.txt','w') as f:
90+
for i in range(len(todo)):
91+
if i==pos+1:
92+
f.write(str(pos)+" "+time+""+''.join(todo[pos+1][p+3:]))
93+
else:
94+
f.write(todo[i])
95+
elif choice==2:
96+
print("Enter your updated work :")
97+
work=input()
98+
p=todo[pos+1].index(":")
99+
y=0
100+
with open('todolist.txt','w') as f:
101+
for i in range(len(todo)):
102+
if i==pos+1:
103+
f.write(str(pos)+" "+''.join(todo[pos+1][p-2:p+3])+" "+work)
104+
else:
105+
f.write(todo[i])
106+
elif n==4:
107+
print("Your Current List: ")
108+
todo=[]
109+
print("____________________________________________________________")
110+
with open('todolist.txt') as f:
111+
for i in f.readlines():
112+
print(i)
113+
todo.append(i)
114+
print("____________________________________________________________")
115+
print("Press 1: Add Item \nPress 2: Delete the Item\nPress 3: Update item\nPress 4:Display Items\nPress 5:Exit")
116+
n=int(input())
117+
118+
119+
120+
print("Thank you for using our application")

0 commit comments

Comments
 (0)