2.5 KiB
2.5 KiB
Hints
The Python comparisons tutorial and Python comparisons examples are a great introduction covering the content of this exercise.
1. Calculate the value of a card
- You can use the equality comparison operator
==to determine if a card is an ace card:card == 'A'. - You can use the containment operator
into determine if a substring is contained inside a string:'Q' in 'KJQ'. - You can use the
intconstructor to convert astrof anintto anint:int('13').
2. Determine which card has a higher value
- Once you have defined the
value_of_cardfunction, you can call it from other functions. - You can use the value comparison operators
>and<to determine if specific cards are greater than or less than a given value:3 < 12. - You can use the equality comparison operator
==to determine if two values are equal to one another.
3. Calculate the value of an ace
- Once you have defined the
value_of_cardfunction, you can call it from other functions. - You can use the order comparison operator
>to decide the appropriate course of action here.
4. Determine Blackjack
- Remember, you can use the
if/elif/elsesyntax to handle different combinations of cards. - You can chain BOTH comparison operators and boolean operators arbitrarily:
y < z < xor(y or z) and (x or z) - You can reuse the already implemented
value_of_cardfunction.
5. Splitting pairs
- You can reuse the already implemented
value_of_cardfunction. - You can handle the
Acase (when at least one of the cards in an ace) separately.
6. Doubling down
- An
Ascored at 11 will never allow doubling down if there are two cards in the hand. - Given the first point, you should be able to reuse the already implemented
value_of_cardfunction. - You can chain comparison operators arbitrarily:
y < z < x. - You can use the conditional expression (sometimes called a "ternary operator")
to shorten simple
if/elsestatements:13 if letter == 'M' else 3.