Hello stars!
Here is my context:
- The function value_of_card(card) works fine;
- I am stuck with the function value_of_ace(card_one, card_two) which I am copyting/pasting below;
- I am getting 2 types of errors:
First type of error: ‘’‘AssertionError: None != 1 : Called value_of_ace(Q, A). The function returned None, but the test expected 1 as the value of an ace card when the hand includes (‘Q’, ‘A’).’‘’
Second type of error: ```AssertionError: 11 != 1 : Called value_of_ace(2, A). The function returned 11, but the test expected 1 as the value of an ace card when the hand includes (‘2’, ‘A’).````
Question: Can you help me finishing this exercise?
def value_of_ace(card_one, card_two):
"""Calculate the most advantageous value for the ace card.
:param card_one, card_two: str - card dealt. See below for values.
:return: int - either 1 or 11 value of the upcoming ace card.
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
2. 'A' (ace card) = 11 (if already in hand)
3. '2' - '10' = numerical value.
"""
value_in_hand = value_of_card(card_one) + value_of_card(card_two)
option_1 = value_in_hand + 1
option_11 = value_in_hand + 11
if option_1 <= 21 and option_11 <=21:
# Compare both options
if (21 - option_1) < (21 - option_11):
return 1
else:
return 11