-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
64 lines (46 loc) · 1.64 KB
/
Copy pathcli.py
File metadata and controls
64 lines (46 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
from functions import get_todo, write_todo
import time
now = time.strftime("%b %d, %Y %H:%M:%S")
print("It is", now)
while True:
user_action = input("Type add, show, edit, complete or exit: ")
user_action = user_action.strip()
if user_action.startswith("add"):
todo = user_action[4:]
todo = todo.title()
todos = get_todo()
todos.append(todo + "\n")
write_todo(todos)
elif user_action.startswith("show"):
todos = get_todo()
new_list = []
for index, new_list in enumerate(todos, 1):
new_list = new_list.strip("\n")
print(f"{index}. {new_list}")
elif user_action.startswith("edit"):
try:
edit_todo_number = int(user_action[5:])
edit_todo_number = edit_todo_number - 1
new_todo = input("Enter a New Todo: ")
todos = get_todo()
todos[edit_todo_number ] = new_todo + " " + "\n"
write_todo(todos)
except ValueError:
print("There is no Item with that number in the list.")
continue
elif user_action.startswith("complete"):
try:
completed_Todo_num = int(user_action[9:])
print("The selected Todo has been marked as completed.")
todos = get_todo()
index = completed_Todo_num - 1
to_remove = todos[index].strip("\n")
todos.pop(index)
write_todo( todos)
except IndexError:
print("Please enter a valid Todo number.")
elif user_action.startswith("exit"):
break
else:
print("Invalid command.")
print("Bye")