Archives January 9, 2023

Add a todo task list for today using python

Code:

#Assign temporary list
tasks = []



#Set the flag and loop through it
flag = True
while flag == True:
    """Add a selection and perform add, view and exit"""
    selection = input("Type 1 for add ,2 for view, 3 for edit and 4 for exit: ")

    if selection == '1':
        task = input("Enter a todo: ")
        tasks.append(task)
    elif selection == '2':
        for x in tasks:
            print(x.title())
    elif selection == '3':
        new_idx = int(input("Enter the item to be edited and updated on the list, there are {0} items in list : ".format(len(tasks))))
        new_idx -= 1
        tasks[new_idx] = input("Enter the task to be updated: ")
        print("Item is successfully updated")
        for x in tasks:
            print(x)
    elif selection == '4':
        flag = 'False'
    else:
        print("Enter the correct option number given above")
        continue
print()
print('**** Exiting the list ****')

O/P:

Type 1 for add ,2 for view, 3 for edit and 4 for exit: 1
Enter a todo: learn
Type 1 for add ,2 for view, 3 for edit and 4 for exit: 1
Enter a todo: play
Type 1 for add ,2 for view, 3 for edit and 4 for exit: 1
Enter a todo: sleep
Type 1 for add ,2 for view, 3 for edit and 4 for exit: 2
Learn
Play
Sleep
Type 1 for add ,2 for view, 3 for edit and 4 for exit: 3
Enter the item to be edited and updated on the list, there are 3 items in list : 2
Enter the task to be updated: fly
Item is updated
learn
fly
sleep
Type 1 for add ,2 for view, 3 for edit and 4 for exit: 4

**** Exiting the list ****

Process finished with exit code 0