Categories: Python
Tags:
# To Do List Creator in Python

tasks = []

while True:
    action = input("Enter 'add', 'remove', or 'show': ")
    if action == "add":
        task = input("Enter task: ")
        tasks.append(task)
    elif action == "remove":
        tasks.pop(0) if tasks else print("No tasks!")
    elif action == "show":
        print(tasks)

This Python program is a simple task manager using a list and a while loop to continuously take user input. It allows users to add, remove, and view tasks dynamically.

  1. Task Storage: An empty list tasks is initialized to store tasks.
  2. User Input Loop: The program runs indefinitely using while True, prompting the user to enter an action: 'add', 'remove', or 'show'.
  3. Adding a Task: If the user enters "add", they are prompted to input a task, which is then appended to the tasks list.
  4. Removing a Task: If the user enters "remove", the program removes the first task (tasks.pop(0)). If the list is empty, it prints "No tasks!" to prevent errors.
  5. Showing Tasks: If the user enters "show", the program prints the current list of tasks.

Features:

  • FIFO (First-In-First-Out) Removal: Tasks are removed in the order they were added, like a queue.
  • Error Handling: It prevents errors by checking if the list is empty before removing a task.
  • Continuous Execution: The program runs indefinitely until manually stopped (Ctrl+C).

Possible Improvements:

  • Allow users to exit the loop.
  • Add task numbering for better management.
  • Provide more removal options (e.g., remove specific tasks).