# Struggling with the black jack exercise

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!

The card is always a `str`. This condition will never be true. `isinstance` checks a data type. It does not check the contents of a string. There are string methods you can use for that, though!

Thank you for the solution!
Turns out, i just need to read the documentation carefully.

While what Isaac says is true, you can simplify your logic even more. Since your if statements check if the card is an A first, it’ll either be true, or false, if false it moves to the next condition. Is it a face card, true or false, then you there is no need to ask the last condition as the other two are already false. To put simply, you have 3 options, if the first two are false, then the last one is automatically true, therefore you can just use the else statement.