Question: Python3: Black jack: def bjack(hand): Returns the score of the blackjack hand. When scoring the hand, number cards are always worth their value and

Python3: Black jack:

def bjack(hand): """ Returns the score of the blackjack hand. When scoring the hand, number cards are always worth their value and face cards (Jack, Queen, King) are always worth 10. However, Aces are either worth 1 or 11, which ever is more advantageous. When determining how to value a hand, the score should be as high as possible without going over 21. If the hand is worth more than 21 points, then all Aces should be worth 1 point. Examples: bjack(('KS','AD')) returns 21 bjack(('KS','9C','AD')) returns 20 bjack(('AS','AC','KH')) returns 12 bjack(('AS','AC','KH','TD')) returns 22 bjack(()) returns 0 Parameter hand: the blackjack hand to score Precondition: hand is a (possibly empty) tuple of 2-character strings representing cards. The first character of each string is '2'-'9', 'T', 'J', 'Q', 'K', or 'A'. The second character of each string is 'H', 'D', 'C', or 'S'. """ # Hint: Keep track of whether you have seen any aces in the hand that are worth 11 # If so, subtract 10 from the accumulator if you go over. pass

---------------------------------------------

Test Cases Below

import func

def test_bjack(): """ Tests procedure for function bjack(). """ print('Testing bjack()') result = func.bjack(()) introcs.assert_equals(0,result) # Test the individual cards result = func.bjack(('2H',)) introcs.assert_equals(2,result) result = func.bjack(('3D',)) introcs.assert_equals(3,result) result = func.bjack(('4C',)) introcs.assert_equals(4,result) result = func.bjack(('5S',)) introcs.assert_equals(5,result) result = func.bjack(('6H',)) introcs.assert_equals(6,result) result = func.bjack(('7D',)) introcs.assert_equals(7,result) result = func.bjack(('8C',)) introcs.assert_equals(8,result) result = func.bjack(('9S',)) introcs.assert_equals(9,result) result = func.bjack(('TH',)) introcs.assert_equals(10,result) result = func.bjack(('JD',)) introcs.assert_equals(10,result) result = func.bjack(('QC',)) introcs.assert_equals(10,result) result = func.bjack(('KS',)) introcs.assert_equals(10,result) result = func.bjack(('AH',)) introcs.assert_equals(11,result) # Now hand combinations result = func.bjack(('2C','TH')) introcs.assert_equals(12,result) result = func.bjack(('3H','5C', '7D', '9S')) introcs.assert_equals(24,result) result = func.bjack(('TS','JD')) introcs.assert_equals(20,result) result = func.bjack(('KS','AD')) introcs.assert_equals(21,result) result = func.bjack(('KS','9C','AD')) introcs.assert_equals(20,result) result = func.bjack(('AS','AC','KH')) introcs.assert_equals(12,result) result = func.bjack(('AS','AC','KH','TD')) introcs.assert_equals(22,result) result = func.bjack(('4H','AS','AD','TC','AH','AC', '2S')) introcs.assert_equals(20,result) result = func.bjack(()) introcs.assert_equals(0,result)

if __name__ == '__main__': test_bjack() print('Module func passed all tests.')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!