Passing todo list into file to store/reload

This commit is contained in:
Kira 2023-09-21 15:08:17 -07:00
parent c36762d240
commit f5afe182a3
3 changed files with 35 additions and 5 deletions

36
main.py
View File

@ -13,39 +13,65 @@
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
# -----------------------------------------------------------------
todos = []
# todos = []
#todo_length = len(todos)
command_prompt = "Type add, show, edit, complete, or exit: "
todo_prompt = "Enter a todo: "
edit_prompt = "Number of todo to edit: "
complete_prompt = "Which todo to mark complete: "
edit_todo = "Enter new todo: "
todo_length = len(todos)
while True:
user_action = input(command_prompt)
user_action = user_action.strip()
match user_action:
case 'add':
todo = input(todo_prompt)
todo = input(todo_prompt) + "\n"
file = open('todos.txt', 'r')
todos = file.readlines()
file.close()
todo = todo.capitalize()
todos.append(todo)
file = open('todos.txt', 'w')
file.writelines(todos)
file.close()
case 'show' | 'display':
file = open('todos.txt', 'r')
todos = file.readlines()
file.close()
for i, todo in enumerate(todos):
text = f"{i}: {todo}"
t = todo.replace("\n","")
text = f"{i+1}: {t}"
print(text)
case 'edit':
file = open('todos.txt', 'r')
todos = file.readlines()
file.close()
which_todo = int(input(edit_prompt)) - 1
new_todo = input(edit_todo)
todos[which_todo] = new_todo
file = open('todos.txt', 'w')
file.writelines(todos)
file.close()
case 'complete':
file = open('todos.txt', 'r')
todos = file.readlines()
file.close()
completed = int(input(complete_prompt)) - 1
completed_message = f"'{todos[completed]}' has been completed!"
print(completed_message)
todos.pop(completed)
print("Remaining todos: ")
for i, todo in enumerate(todos):
text = f"{i}: {todo}"
t = todo.replace("\n","")
text = f"{i+1}: {t}"
print(text)
file = open('todos.txt', 'w')
file.writelines(todos)
file.close()
case 'exit':
break
case _:

0
todo.txt Normal file
View File

4
todos.txt Normal file
View File

@ -0,0 +1,4 @@
Show
Read
Not this
Or this