File tree Expand file tree Collapse file tree
exercises/concept/card-games Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,7 +52,14 @@ def approx_average_is_average(hand):
5252 :return: bool - is approximate average the same as true average?
5353 """
5454
55- return card_average ([hand [0 ], hand [- 1 ]]) == card_average (hand )
55+ real_average = card_average (hand )
56+ if card_average ([hand [0 ], hand [- 1 ]]) == real_average :
57+ is_same = True
58+ elif hand [len (hand ) // 2 ] == real_average :
59+ is_same = True
60+ else :
61+ is_same = False
62+ return is_same
5663
5764
5865def average_even_is_average_odd (hand ):
Original file line number Diff line number Diff line change @@ -60,9 +60,9 @@ def test_empty(self):
6060 want = []
6161
6262 self .assertEqual (concatenate_rounds (rounds_1 , rounds_2 ),
63- want ,
64- msg = f'Expected { want } but got an incorrect result.'
65- )
63+ want ,
64+ msg = f'Expected { want } but got an incorrect result.'
65+ )
6666
6767 @pytest .mark .task (taskno = 2 )
6868 def test_other (self ):
@@ -209,6 +209,18 @@ def test_instructions_example_3(self):
209209 msg = f'Expected { want } but got an incorrect result: { got !r} '
210210 )
211211
212+ @pytest .mark .task (taskno = 5 )
213+ def test_median_true (self ):
214+ hand = [1 , 2 , 4 , 5 , 8 ]
215+ want = True
216+ got = approx_average_is_average (hand )
217+
218+ self .assertEqual (
219+ want ,
220+ got ,
221+ msg = f'Expected { want } but got an incorrect result: { got !r} '
222+ )
223+
212224 @pytest .mark .task (taskno = 5 )
213225 def test_other_true (self ):
214226 hand = [2 , 3 , 4 ]
You can’t perform that action at this time.
0 commit comments