Struck with card games approx_average_is_average()

def card_average(hand):
return sum(hand)/len(hand)

def approx_average_is_average(hand):
approx_ave=(hand[0]+hand[-1])/2
if (approx_ave)==(card_average(hand)):
return True
return False

This is my code. It passed all the 7 test except 1. I don’t know what to do. please help me.

Below is the failed Testcase:

AssertionError: False != True : Called approx_average_is_average([1, 2, 4, 5, 8]). The function returned False, but the hand [1, 2, 4, 5, 8] does yield the same approximate average.

You will want to use code blocks for this, as Python is very much a “white space matters” language, and this would not be valid as presented for any of the tests.

You can do so by using three backticks ‘~’ characters, the language name, and then paste the code in, and end it with three backticks.

def card_average(hand):
    return sum(hand)/len(hand)

The effect of doing so can be seen above.

Without seeing the actual code, it is difficult to see exactly what you may have correct and what you may have incorrect.

That said, the fact that you get a false response for the test, but true was expected, you will want to ensure that the values that you are comparing are in fact equal.

Double check what the instructions say for the approximate average. There are multiple ways to compute an approximate.

1 Like