so i was playing around with python if else loop to deepen my understanding with recursion. But i had a problem with this particular one.
I have a list of 5 integers, and if there is any odd number in the list, change allEven boolean logic to False. But however, my current code returns me None instead.
def areEven(l):
if len(l) != 0:
if l[0] % 2 == 0:
allEven = True
l.pop(0)
areEven(l)
else:
allEven = False
else:
return areEven(l)
print('All are even is',areEven([2,4,6,8,11]))
Is there something wrong with this code, or is it me that understood recursion wrongly?(Note that i can only use a if else statement and not any other loops)
Aucun commentaire:
Enregistrer un commentaire