DEV Community

Cover image for Learn Python Data Structures
Brian Kanyi Karanja
Brian Kanyi Karanja

Posted on

Learn Python Data Structures

Shopping Cart Example

Create a program that starts with an empty list. Ask the user to input 3 tasks. Add them to the list, then "complete" the second task by removing it from the list. Finally, print the remaining tasks in alphabetical order.

#Add Empty list
tasks= [];


for i in range(3):
    task = input(f"Enter task {i+1}: ")
    tasks.append(task)


print(f"\nYour curent task: {tasks}")

completed_task = tasks.pop(1)
print(f"\n Completed task: {completed_task}")


remaining_tasks = sorted(tasks)
print(f"\nRemaining tasks (alphabetical order): ")

for task in remaining_tasks:
    print(f"- {task}")

Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
brian001 profile image
Brian Kanyi Karanja • Edited

How best can we solve the question?