jeudi 12 juillet 2018

Is it possible to make my else statement appear after the code is done checking every option?

I have a while loop that goes over a two-dimensional list, to see if it can find a similar submission for it to be removed.

    i=0

while i <= len(list):
    if list[i] == userinput:
        del list[i]
        print("Entry Removed!")
    else:
        print("This publication does not exist")
    i+=1

What I wanted was for the code to print the message "This publication does not exist" if no matches were found. However, what happens right now is that everytime it compares an item, the code prints the sentence.

I understand why this happens but I have no idea how to fix it. What is the best way of addressing this issue?

Aucun commentaire:

Enregistrer un commentaire