PDA Assignments
  • Python For Data Analytics
    • 1.Python
      • 1.Python Documents
        • 1.Data Types
        • 2.Variables In Python
        • 3.Operators In Python
        • 4.User Input In Python
        • 5.TypeCasting In Python
        • 6.Strings In Python
        • 7.Conditional Statements In Python
        • 8.Branching using Conditional Statements and Loops in Python
        • 9.Lists In Python
        • 10.Sets In Python
        • 11.Tuples In Python
        • 12.Dictionary In Python
        • 13.Functions In Python
        • 14.File Handling In Python
        • 15.Numerical Computing with Python and Numpy
      • 2.Python Assignments
        • Data Type & Variables
        • Operators Assignment
        • User Input & Type Casting
        • Functions- Basic Assignments
        • String Assignments
          • String CheatSheet
        • Conditional Statements Assignments
        • Loops Assignments
        • List Assignments
          • List Cheatsheet
        • Set Assignments
          • Sets Cheatsheet
        • Dictionary Assignments
          • Dictionary Cheatsheet
        • Function Assignments
        • Functions used in Python
      • 3.Python Projects
        • Employee Management System
        • Hamming distance
        • Webscraping With Python
          • Introduction To Web Scraping
          • Importing Necessary Libraries
          • Basic Introduction To HTML
          • Introduction To BeautifulSoup
          • Flipkart Web Scraping
            • Scraping Step By Step
        • Retail Sales Analysis
        • Guess the Word Game
        • Data Collection Through APIs
        • To-Do List Manager
        • Atm-functionalities(nested if)
        • Distribution of Cards(List & Nested for)
        • Guess the Number Game
      • 4.Python + SQL Projects
        • Bookstore Management System
    • 2.Data Analytics
      • 1.Pandas
        • 1.Pandas Documents
          • 1.Introduction To Pandas
          • Reading and Loading Different Data
          • 2.Indexing and Slicing In Pandas
          • 3.Joining In Pandas
          • 4.Missing Values In Pandas
          • 5.Outliers In Pandas
          • 6.Aggregating Data
          • 7.DateTime In Pandas
          • 8.Validation In Pandas
          • 9.Fetching Data From SQL
          • 10. Automation In Pandas
          • 11.Matplotlib - Data Visualization
          • 12. Seaborn - Data Visualization
          • 13. Required Files
        • 3.Pandas Projects
          • Retail Sales Analysis
            • Retail Sales Step By Step
          • IMDB - Dataset Analysis - Basic
        • 2. Pandas Assignments
          • 1. Reading and Loading the Data
          • 2. Data frame Functions and Properties
          • 3. Series - Basic Operations
          • 4. Filtering in Pandas
          • 5. Advance Filtering
          • 6. Aggregate Functions & Groupby
          • 7. Pivot Tables
          • 8. Datetime
          • 9. String Functions
Powered by GitBook
On this page
  • 3.Function to view tasks
  • 4. Function to delete task
  • Creating a menu and calling the functions as per user's choice
  1. Python For Data Analytics
  2. 1.Python
  3. 3.Python Projects

To-Do List Manager

Create a simple to-do list manager where users can add, view, and delete tasks from their to-do list. The program should provide a menu-driven interface for users to interact with their tasks.

Let's go through each function in the code and explain their purpose:

  1. Create a variable tasks of list data type that contains no item.

tasks=[]
  1. Function to add a task

add_task() :This function is responsible for adding a task to the tasks list. It prompts the user to enter a new task using the input() function. The entered task is then appended to the tasks list using the append() method. Finally, it prints a message to confirm that the task has been added successfully.

def add_task():
    task = input("Enter a new task: ")
    tasks.append(task)
    print("Task added successfully!")

3.Function to view tasks

view_tasks(): This function displays all the tasks in the tasks list. It first checks if the list is empty using a conditional statement. If the list is not empty, it iterates over the tasks using the enumerate() function. The enumerate() function provides both the index and the value of each task in the list. It then prints each task along with its corresponding index number. If the list is empty, it prints a message indicating that the task list is empty.

def view_tasks():
    if tasks:
        print("Your tasks:")
        for i, task in enumerate(tasks, start=1):
            print(f"{i}. {task}")
    else:
        print("Your task list is empty.")

4. Function to delete task

delete_task(): This function allows the user to delete a task from the tasks list. First, it calls the view_tasks() function to display the current tasks. It then prompts the user to enter the number of the task they want to delete. The input is converted to an integer and subtracted by 1 to align with the zero-based indexing of the list. Next, it checks if the entered task index is valid by comparing it with the range of valid indices in the list. If the index is valid, it uses the pop() method to remove the task at the specified index from the tasks list. It also prints a message to confirm the deletion of the task. If the entered index is invalid, it prints an error message.

def delete_task():
    view_tasks()
    task_index = int(input("Enter the task number to delete: ")) - 1
    if 0 <= task_index < len(tasks):
        deleted_task = tasks.pop(task_index)
        print(f"Deleted task: {deleted_task}")
    else:
        print("Invalid task number!")

Creating a menu and calling the functions as per user's choice

Here, we are going to create a menu for the user to select the kind of task he wants to do.

while True:
        print("\n-- To-Do List Manager --")
        print("1. Add Task")
        print("2. View Tasks")
        print("3. Delete Task")
        print("4. Exit")

        choice = input("Enter your choice (1-4): ")

        if choice == "1":
            add_task()
        elif choice == "2":
            view_tasks()
        elif choice == "3":
            delete_task()
        elif choice == "4":
            print("Goodbye!")
            break
        else:
            print("Invalid choice. Please try again.")

PreviousData Collection Through APIsNextAtm-functionalities(nested if)

Last updated 1 year ago