Answered step by step
Verified Expert Solution
Link Copied!

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
todo_list =[]
completed_tasks = set()
def clear_screen():
os.system("cls" if os.name =="nt" else "clear")
def display_menu():
clear_screen()
print("***********")
print("Todoify")
print("-----------")
print("list List todos")
print("add Add todo")
print("check Check todo")
print("delete Delete todo")
print("save Save todos to file")
print("load Load from file")
print("------------------")
def display_todo_list():
unique_todo_list = list(set(todo_list)) # Remove duplicates
if not unique_todo_list:
print("No tasks in the to-do list.")
else:
for i, task_item in enumerate(unique_todo_list):
checkbox ="[x]" if i in completed_tasks else "[]"
print(f"{checkbox}{task_item}")
input("Press enter to continue...")
def add_task(task_item):
todo_list.append(task_item)
print("SUCCESS: Todo added")
input("Press enter to continue...")
def check_task(task_index_to_check):
if 1<= task_index_to_check <= len(todo_list):
if task_index_to_check -1 not in completed_tasks:
print("SUCCESS: UNCHECKED -> CHECKED")
completed_tasks.add(task_index_to_check -1)
else:
print("Task already checked.")
time.sleep(2)
else:
print("Invalid task index.")
input("Press enter to continue...")
def delete_task(task_index_to_delete):
if 1<= task_index_to_delete <= len(todo_list):
deleted_task = todo_list.pop(task_index_to_delete -1)
print(f"SUCCESS: Todo '{deleted_task}' deleted from the to-do list.")
print("---------------------")
display_todo_list() # Display remaining todos
else:
print("Invalid task index.")
input("Press enter to continue...")
def save_to_file():
with open("todo_list.json", "w") as file:
json.dump(todo_list, file)
print("SUCCESS: To-do list saved to file")
print("INFO: This web demo does not actually support saving todos to file.")
input("Press enter to continue...")
def load_from_file():
global todo_list
try:
with open("todo_list.json", "r") as file:
todo_list = json.load(file)
except FileNotFoundError:
pass
print("SUCCESS: To-do list loaded from file")
print("INFO: This web demo does not actually support loading of todos.")
input("Press enter to continue...")
# Initial display menu
display_menu()
while True:
display_menu()
choice = input("Selection >")
# Print separator line below the user makes a selection
print("-------------------------")
if choice == "list":
display_todo_list()
elif choice == "add":
task = input("Todo description >")
add_task(task)
elif choice == "check":
task_index = int(input("Enter the task index to check: "))
check_task(task_index)
elif choice == "delete":
task_index = int(input("Enter the task index to delete: "))
delete_task(task_index)
elif choice == "save":
save_to_file()
elif choice == "load":
load_from_file()
elif choice == "exit":
print("Exiting...")
break
else:
print("Invalid choice. Please enter a valid command.")
input("Press 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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Integrated Accounting

Authors: Dale A. Klooster, Warren Allen, Glenn Owen

8th edition

1285462726, 1285462721, 978-1285462721

More Books

Students also viewed these Programming questions

Question

How flying airoplane?

Answered: 1 week ago

Question

Describe the process for deleting a general journal entry.

Answered: 1 week ago