mercredi 13 février 2019

Why does debug skips elif lst[0] in speech in if statement

speech = ["cs", "is", "fun", "homework", "is", "sometimes", "fun", \
 "exams", "are", "not", "fun"]

lst = ["fun", "is", "not"]

def number(speech,lst,total_sofar):
    if len(lst) == 0:
        return total_sofar
    elif lst[0] in speech == False:
        return number(speech, lst[1:],total_sofar)
    else:
        speech[speech.index(lst[0])] = "<redact>"
        total_sofar = total_sofar +1
        return number(speech,lst,total_sofar)

the error it gives is that "fun" is not found and when i run debug it skips elif statement even when "fun" is no longer in speech.

Aucun commentaire:

Enregistrer un commentaire