import json
import os
import time
todolist
completedtasks set
def clearscreen:
ossystemcls if osname nt else "clear"
def displaymenu:
clearscreen
print
printTodoify
print
printlist List todos"
printadd Add todo"
printcheck Check todo"
printdelete Delete todo"
printsave Save todos to file"
printload Load from file"
print
def displaytodolist:
uniquetodolist listsettodolist # Remove duplicates
if not uniquetodolist:
printNo tasks in the todo list."
else:
for i taskitem in enumerateuniquetodolist:
checkbox x if i in completedtasks else
printfcheckboxtaskitem
inputPress enter to continue..."
def addtasktaskitem:
todolist.appendtaskitem
printSUCCESS: Todo added"
inputPress enter to continue..."
def checktasktaskindextocheck:
if taskindextocheck lentodolist:
if taskindextocheck not in completedtasks:
printSUCCESS: UNCHECKED CHECKED"
completedtasks.addtaskindextocheck
else:
printTask already checked."
time.sleep
else:
printInvalid task index."
inputPress enter to continue..."
def deletetasktaskindextodelete:
if taskindextodelete lentodolist:
deletedtask todolist.poptaskindextodelete
printfSUCCESS: Todo deletedtask deleted from the todo list."
print
displaytodolist # Display remaining todos
else:
printInvalid task index."
inputPress enter to continue..."
def savetofile:
with opentodolist.json", w as file:
json.dumptodolist, file
printSUCCESS: Todo list saved to file"
printINFO: This web demo does not actually support saving todos to file."
inputPress enter to continue..."
def loadfromfile:
global todolist
try:
with opentodolist.json", r as file:
todolist json.loadfile
except FileNotFoundError:
pass
printSUCCESS: Todo list loaded from file"
printINFO: This web demo does not actually support loading of todos."
inputPress enter to continue..."
# Initial display menu
displaymenu
while True:
displaymenu
choice inputSelection
# Print separator line below the user makes a selection
print
if choice "list":
displaytodolist
elif choice "add":
task inputTodo description
addtasktask
elif choice "check":
taskindex intinputEnter the task index to check:
checktasktaskindex
elif choice "delete":
taskindex intinputEnter the task index to delete:
deletetasktaskindex
elif choice "save":
savetofile
elif choice "load":
loadfromfile
elif choice "exit":
printExiting
break
else:
printInvalid choice. Please enter a valid command."
inputPress enter to continue..."
# Print separator line under the user makes a selection
print