# This is a sample Python script. # Press Shift+F10 to execute it or replace it with your code. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. #def print_hi(name): # Use a breakpoint in the code line below to debug your script. # print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint. # Press the green button in the gutter to run the script. #if __name__ == '__main__': # print_hi('PyCharm') # See PyCharm help at https://www.jetbrains.com/help/pycharm/ # ----------------------------------------------------------------- # 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: " while True: user_action = input(command_prompt) user_action = user_action.strip() match user_action: case 'add': 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): 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): 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 _: print("Unrecognized command; please try again.") print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") print("Goodbye!")