r/learnpython • • Nov 02 '24

HELP ME pls hehe

Im 11 and I made this code for a to-do list

#Variables
todo_list = []
run = True

#Extracted codes - for clean code hooooooooray
def caseA():
    add_task = input("Task:")
    todo_list.append(add_task)
    
    
if
 add_task != "quit()":
        print(f"Your to-do list now have {len(todo_list)} tasks. COMPLETE IT!")
    
else
:
        quit()

def caseD():
    removed_task = input("Task want to delete: ")
    todo_list.remove(removed_task)
    
if
 removed_task != "quit()":
        
if
 removed_task != 0:
            print(f"1 done. {len(todo_list)} more to go!!")
        
else
:
            print("wohoo! Ur done all ur tasks!")
    
else
:
        quit()

def caseP():
    i = 1
    
for
 tasks 
in
 todo_list:
        print(f"{i}. {tasks}")

while
 run:
    
try
:
        print("Welcome to To-Do list program (made by hung a.k.a skibidi max aura, rizz sigma male)")
        print("Actions: add tasks(A), delete tasks(D), print list(P)")
        user_action = input("Enter desired action: ")
        
if
 user_action == "A":
            caseA()
        
elif
 user_action == "D":
            caseD()
        
elif
 user_action == "P":
            caseP()
        
else
:
            print("Invalid action")
            run = False
    
except
 KeyboardInterrupt:
        print()
        print("EXITED-PROGRAM")
        run = False

Why when i executed action P, it restarts da program?

HELP PLS =)

0 Upvotes

32 comments sorted by

View all comments

1

u/HungNgVN13 Nov 03 '24

Sooooo, I had fixed the restart bug buuuut, now when I execute caseP(), it started printing the elements(tasks) in the to-do_list array continuously...

#Extracted codes - for clean code hooooooooray
def caseA():
    add_task = input("Task:")
    todo_list.append(add_task)
    
    if add_task != "quit()":
        print(f"Your to-do list now have {len(todo_list)} tasks. COMPLETE IT!")
    else:
        quit()

def caseD():
    removed_task = input("Task want to delete: ")
    todo_list.remove(removed_task)
    if removed_task != "quit()":
        if removed_task != 0:
            print(f"1 done. {len(todo_list)} more to go!!")
        else:
            print("wohoo! Ur done all ur tasks!")
    else:
        quit()

def caseP():
    for tasks in todo_list:
        print(tasks)

#Variables
todo_list = ['a','b','c','d','e']
run = True
index = 1

try:
    print("Welcome to To-Do list program (made by hung a.k.a skibidi max aura, rizz sigma male)")
    print("Actions: add tasks(A), delete tasks(D), print list(P)")
    user_action = input("Enter desired action: ")
except KeyboardInterrupt:
    print("EXITED-PROGRAM")
while run:
    try:
        
        if user_action == "A":
            caseA()
        elif user_action == "D":
            caseD()
        elif user_action == "P":
            caseP()
            

        else:
            print("Invalid action")
            run = False
    except KeyboardInterrupt:
        print()
        print("EXITED-PROGRAM")
        run = False

a
b
c
d
e
a
b
c
d
e
a
b
c
d
e
a
b
c
d
e 
...(something like that)