[Python] Not getting the correct output since i changed match case to if else

Discussão em 'Python' iniciado por Stack, Maio 27, 2025.

  1. Stack

    Stack Membro Participativo

    So I'm currently working on a todo list in python and since i made a small change in my code there's been a problem with the output

    while True:
    user_choice = input("Type add, show, edit, complete or exit: ")
    user_choice = user_choice.strip()

    if 'add' in user_choice or 'new' in user_choice:
    task = user_choice[4:]

    with open ('tasks.txt','r') as file:
    tasks=file.readlines()

    tasks.append(task)

    with open ('tasks.txt','w') as file:
    file.writelines(tasks)


    elif 'show' in user_choice:

    with open ('tasks.txt','r') as file:
    tasks = file.readlines()

    for index,item in enumerate(tasks):
    item = item.strip('\n')
    row = f"{index+1}-{item}"
    print(row)


    In this block every time I add a task in this it gets added right next to the existing task instead of being added to a new one

    I want it to add tasks in different lines instead of just joining them in a single line

    Continue reading...

Compartilhe esta Página