lundi 3 février 2020

Python: Can somebody please explain why the elif statement in my code returns None

I was practicing some online Python exercise problems and I am stuck with a thing here.

To cut to the chase, the following is my goal in this coding exercise

Question: Write a function that returns the lesser of two given numbers if both numbers are even, but returns the greater if one or both numbers are odd

Here is my code:

def funct(a,b):
    if a%2 == 0 and b%2 == 0: 
        return min(a,b)
    elif a%2 != 0 and b%2 !=0:
        return max(a,b)

funct(2,5)

>> None

If I write else instead of elif, then this seems to work well. But I don't understand why elif statement returns None

Aucun commentaire:

Enregistrer un commentaire