mardi 21 mai 2019

The specific case won't pass elif on line 8:

I'm solving puzzles on Dcoder, I decided to hard code the solution, and it still didn't pass all the tests.

I expanded the code to what it is now (the code that I pasted) to include all of the cases I could think of. I found a specific case that it should pass, but for some reason that doesn't happen.

I also tried adding brackets in if/elif block, but that didn't change anything (I didn't expect it to, but I still tried)

def damn(a, b, c, d, n, m):
    if a+c <= n:
        if b <= m and d <= m:
            return True
    elif a+d <= n:
        if b <= m and c <= m:
            return True
    elif a+c <= m:
        if b <= n and d <= n:
            return True
    elif a+d <= m:
        if b <= n and c <= n:
            return True
    elif b+c <= n:
        if a <= m and d <= m:
            return True
    elif b+d <= n:
        if a <= m and c <= m:
            return True
    elif b+c <= m:
        if a <= n and d <= n:
            return True
    elif b+d <= m:
        if a <= n and c <= n:
            return True
    else:
        return False

if damn(2, 2, 1, 4, 4, 3):
    print("Yes")
else:
    print("No")

elif a+c <= m:
        if b <= n and d <= n:
            return True

That should be:

3 <= 3

2 <= 4 and 4 <= 4

output of all is true, those are the values that come up when I print them before if/elif/else block, yet for some reason function "damn" returns false.

Does anyone have an idea why does that happen and can you explain it?

Aucun commentaire:

Enregistrer un commentaire