#Python Black Black Jack ✅

41 messages · Page 1 of 1 (latest)

peak crane
#

Hello everyone I need help with Black Jack exercise 6

Exercism.org/tracks/python/exercises/black-jack/edit

Task 3 Calculate the value of an ace

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. """
total_of_hand = value_of _card( card_one) + value_of_card(card_two)```
  ```python
return 1 if total_of_hand  + 11 > 21 or 'A' in [card_one, card_two] else 11```
hidden foxBOT
fluid thunder
#

Do you need help with task #6 "Doubling Down" on the Black Jack exercise?
Do you understand the instructions?
Do you have a (maybe vague) idea how to solve it?
Did you write some code?
Did you run the tests?
What does the error message from the failed tests say?

peak crane
#

Value_error and 👇

fluid thunder
#

This looks like task #3 "Calculate the value of an ace", right?
Do you mind editing your post and putting the code in a "code block" (see the comment above)?
Otherwise the formatting is off and some characters get interpreted as markup.

#

@peak crane You still there?

peak crane
fluid thunder
#

Do you mind editing your post?

#

Put one line with three backticks (```) before the code, and another line with three backticks after the code.

#

One last time, please: Put the whole function (starting with def ..., ending with return 11) into one code block.

#

The test calls value_of_ace(2, 'A') and expects the result 1.
Do you understand why that result is correct?

near oxide
#
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.
    """

     # Ensure there is at least one ace in the hand

    if 'A' not in [card_one, card_two]:
        raise ValueError
        return None
    
    # Calculate the total value of non-ace cards
    if card_one == 'A' and card_two == 'A':
        return 11
fluid thunder
#

Do you understand why your implementation returns None?

#

@near oxide : are you sure about the indentation of the last two lines?

near oxide
#

No. Copy paste on a phone is hard 😁

fluid thunder
#

Let me post my questions again:
The test calls value_of_ace(2, 'A') and expects the result 1.
Do you understand why the expected result 1 is correct?
Do you understand why your implementation returns None?

peak crane
near oxide
#

What return line do you expect to be executed when the function is called with those values?

#

Is one of the cards 'A' in that test?

peak crane
near oxide
#

(yes/no)?

peak crane
near oxide
#

Then that condition wouldn't match and that return line wouldn't be executed

#

If 'A' not in [card_one, card_two] is only matched when there is no 'A' card

#

So ... do you expect that return line to be executed? Some other return line?

peak crane
near oxide
#

It's really hard to reason about code based on snippets. Please share the complete function

#

Note this function is supposed to return the value of a third card, an ace, assuming two cards are already in the hand.

peak crane
peak crane
near oxide
#
  1. Please share your code.
  2. What do you expect the function to do with that input?
  3. Do you understand why 1 is the correct result.
#

It helps if you actually answer the questions 🙂

peak crane
near oxide
#

Did you solve the exercise? Because you didn't answer any of my questions 😁

peak crane
peak crane
near oxide
#

🎉

hidden foxBOT
#

If everything is resolved, we ask that the person who posted the request react to the top/original post with a :white_check_mark: (:white_check_mark:). This indicates to others that this issue has been resolved and locks the thread.
If all the tests pass and you want to further improve your solution, we encourage you to use the "Request a Code Review" feature on the website!

peak crane
#

Python Black Black Jack ✅

near oxide
#

"react" not update title