I constantly get this errror that ‘int’ object is not iterable, but in the test result the elements of the list are also lists and are not int type, how can I fix it?
def approx_average_is_average(hand):
"""Return if the (average of first and last card values) OR ('middle' card) == calculated average.
average = card_average(hand)
first_way = (card_average(hand[0]) + card_average(hand[-1]))/2
med = (len(hand)+1)/2
sec_way = hand[med]
return average == first_way or average == sec_way
Code Run
input_data = [[0, 1, 5], [3, 6, 9, 12, 150], [1, 2, 3, 5, 9],
[2, 3, 4, 7, 8], [1, 2, 3], [2, 3, 4],
[2, 3, 4, 8, 8], [1, 2, 4, 5, 8]]
result_data = [False, False, False, False, True, True, True, True]
for variant, (hand, expected) in enumerate(zip(input_data, result_data), start=1):
with self.subTest(f'variation #{variant}', hand=hand, expected=expected):
actual_result = approx_average_is_average(hand)
error_message = (f'Called approx_average_is_average({hand}). '
f'The function returned {actual_result}, but '
f'the hand {hand} {"does" if expected else "does not"} '
f'yield the same approximate average.')
self.assertEqual(actual_result, expected, msg=error_message)
Test Failure
TypeError: ‘int’ object is not iterable