[Python] Can I do this without using a dictionary [closed]

Discussão em 'Python' iniciado por Stack, Julho 1, 2025.

  1. Stack

    Stack Membro Participativo

    I want the mark_as_completed function to display the active tasks added to the todo list, prompt for an index and move the selected task from the active list to a separate completed_tasks list. However, when I type in the index(for example, 1 for the first task), it doesn't seem to be satisfying the condition on the if statement and just keeps printing 'invalid choice' from the else statement.

    def mark_as_completed():
    for index, item in enumerate(todo, start = 1):
    print(f'{index}. {item.capitalize()}')
    completed = int(input('Add completed task??\n'))
    if completed in todo:
    complete = todo.pop(completed)
    completed_tasks.append(complete)
    else:
    print('Invalid choice\n')


    The completed_tasks and todo list has been initialized outside this function

    Continue reading...

Compartilhe esta Página