Hello there,
I keep getting and error and i just cant get my head around it. Could anyone explain to me why my code doesn’t work?
def value_of_ace(card_one, card_two):
if ('A' in card_one or card_two): return 1
return 11 if (value_of_card(card_one) + value_of_card(card_two) <= 10) else 1
I don’t think there should be an error with this code
If there is not an ace on my hand then it should not run line 2 and pass from line 2 to line 3 where it check the sum of the two cards in hand and give 11 if the sum is less or equal to 10 or 1 if it is above 10
Thank you for the help in advance
I am so confused now.
OK! so… I moved a bit with the code and change this from line 2
if ('A' in card_one or card_two): return 1
>> to >>
if (card_one == 'A' or card_two == 'A'): return 1
And now it works… this is so confusing to me because it is saying the same thing.
It all comes down to readability, because functionality there is no difference. Or is there, and I can’t see it?
IsaacG
January 24, 2024, 12:26am
3
if ('A' in card_one) or (card_two)
The bit after the or will always be true.
Now i get the difference! Thank you very much, really appreciated.
So it should be:
if ('A' in card_one or 'A' in card_two): return 1
Got it. Again thank you very much
IsaacG
January 24, 2024, 12:44am
5
if card_one == 'A' or card_two == 'A'
if 'A' in (card_one, card_two)
Your code has a Yoda condition and is using in
to compare strings.