Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This code does not clear between functions, and the menu display is repetitive. Display menu must remain and not repeat. Then in the check and
This code does not clear between functions, and the menu display is repetitive. Display menu must remain and not repeat. Then in the check and delete function, the enter index should be displayed after displaying the list.
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
Step by Step Solution
★★★★★
3.44 Rating (157 Votes )
There are 3 Steps involved in it
Step: 1
Heres the modified code import json import os import time todolist completedtasks ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started