The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Create daily to-do lists with Python

To create a daily to-do list in Python, you can use simple data structures like lists or dictionaries. Here’s an example of how you can create a basic daily to-do list and interact with it (e.g., adding tasks, marking tasks as completed).

python
# Daily To-Do List Program # Create an empty list to store tasks tasks = [] def display_tasks(): print("nToday's To-Do List:") if not tasks: print("No tasks for today!") else: for idx, task in enumerate(tasks, 1): print(f"{idx}. {task['task']} - {'Done' if task['done'] else 'Pending'}") def add_task(): task = input("nEnter a task: ") tasks.append({'task': task, 'done': False}) print(f"Task '{task}' added to your to-do list.") def mark_task_done(): display_tasks() try: task_num = int(input("nEnter the task number to mark as done: ")) if 1 <= task_num <= len(tasks): tasks[task_num - 1]['done'] = True print(f"Task '{tasks[task_num - 1]['task']}' marked as done.") else: print("Invalid task number.") except ValueError: print("Please enter a valid task number.") def remove_task(): display_tasks() try: task_num = int(input("nEnter the task number to remove: ")) if 1 <= task_num <= len(tasks): removed_task = tasks.pop(task_num - 1) print(f"Task '{removed_task['task']}' removed from your to-do list.") else: print("Invalid task number.") except ValueError: print("Please enter a valid task number.") def main(): while True: print("n--- Daily To-Do List ---") print("1. Display Tasks") print("2. Add Task") print("3. Mark Task as Done") print("4. Remove Task") print("5. Exit") try: choice = int(input("nEnter your choice: ")) if choice == 1: display_tasks() elif choice == 2: add_task() elif choice == 3: mark_task_done() elif choice == 4: remove_task() elif choice == 5: print("Exiting. Have a productive day!") break else: print("Invalid choice, please choose a valid option.") except ValueError: print("Invalid input, please enter a number between 1 and 5.") # Start the program if __name__ == "__main__": main()

How it works:

  1. Tasks Storage: The tasks are stored as a list of dictionaries. Each dictionary contains the task and a done status.

  2. Displaying Tasks: It shows the list of tasks with their status (done or pending).

  3. Adding Tasks: The user can add new tasks by entering them through the console.

  4. Marking Tasks as Done: The user can mark tasks as completed.

  5. Removing Tasks: The user can remove tasks from the list.

How to Use:

  • Run the script.

  • You can choose to display, add, mark as done, or remove tasks.

  • You can exit when you’re done.

Would you like to add more features to this?

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About