0% found this document useful (0 votes)
2 views3 pages

Python 7

The document outlines a Python program that manages a task list with functionalities to add, update, remove, sort tasks, and exit the program. It includes user input handling for task management and error checking for invalid inputs. The program runs in a loop until the user chooses to exit.

Uploaded by

nitishgokhale85
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Python 7

The document outlines a Python program that manages a task list with functionalities to add, update, remove, sort tasks, and exit the program. It includes user input handling for task management and error checking for invalid inputs. The program runs in a loop until the user chooses to exit.

Uploaded by

nitishgokhale85
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROGRAM

def main():

# Initialize an empty list to store tasks

tasks = []

while True:

# Display the current list and available actions

print(f"\nTasks: {tasks}")

print("1: Add, 2: Update, 3: Remove, 4: Sort, 5: Exit")

choice = input("Action: ")

# 1. ADD TASK

if choice == "1":

new_task = input("New task: ")

[Link](new_task)

# 2. UPDATE TASK

elif choice == "2" and tasks:

try:

idx = int(input("Task number (1, 2...): ")) - 1

if 0 <= idx < len(tasks):

tasks[idx] = input("New description: ")

else:

print("Invalid task number.")

except ValueError:

print("Please enter a number.")


# 3. REMOVE TASK

elif choice == "3" and tasks:

try:

idx = int(input("Task number (1, 2...): ")) - 1

if 0 <= idx < len(tasks):

print(f"Removed: {[Link](idx)}")

else:

print("Invalid task number.")

except ValueError:

print("Please enter a number.")

# 4. SORT TASKS

elif choice == "4":

[Link]()

print("Sorted alphabetically!")

# 5. EXIT

elif choice == "5":

print("Goodbye!")

break

else:

print("Invalid input or no tasks available.")

if __name__ == "__main__":

main()
OUTPUT

You might also like