0

One of the functions I figure I need to make a black jack game:

The function

def card_value_dealer(card_variable):
    if card_variable == 'A':
        return 11
    elif card_variable == 'J' or 'Q' or 'K':
        return 10
    else:
        return card_variable

print(card_value_dealer(7))

In this instance I would expect the function to return 7, but here and for every other parameter value it always returns 10 (except for when the parameter is 'A', then it does return the correct value 11).

Why is this happening?

Sondr
  • 35
  • 3

1 Answers1

1

The condition elif card_variable == 'J' or 'Q' or 'K' isn't doing what you think it's doing. It is first checking if card_variable has the value 'J' and then, if that is false, goes on to check if the boolean expression 'Q' is true, which in this case is just a literal value, which is always true.

What you presumably want is to check if the value is in a list of certain values, which can be done like so: elif card_variable in ('J', 'Q', 'K'):

Etienne Ott
  • 656
  • 5
  • 14