Hi!
It’s my first time using exercism and I’m new to programming (I just started 2 weeks ago).
Right now I’m stuck at the first task of black jack exercise (Calculate the value of a card)
this is my code
def value_of_card(card):
"""Determine the scoring value of a card.
:param card: str - given card.
:return: int - value of a given card. See below for values.
1. 'J', 'Q', or 'K' (otherwise known as "face cards") = 10
2. 'A' (ace card) = 1
3. '2' - '10' = numerical value.
"""
if card == 'A':
return 1
elif card in ['K', 'J', 'Q']:
return 10
elif isinstance(card, int):
return int(card)
else:
pass
and this is the code run
test_data = [('2', 2), ('5', 5), ('8', 8),
('A', 1), ('10', 10), ('J', 10),
('Q', 10), ('K', 10)]
for variant, (card, expected) in enumerate(test_data, 1):
with self.subTest(f'variation #{variant}', card=card, expected=expected):
actual_result = value_of_card(card)
error_msg = (f'Called value_of_card({card}). '
f'The function returned {actual_result} as the value of the {card} card, '
f'but the test expected {expected} as the {card} card value.')
self.assertEqual(actual_result, expected, msg=error_msg)
I hope there is someone who can explain or give me a clue as to why my code doesn’t work.
Thank you!