Loading…
None
String updated in the repository |
|
None
String updated in the repository |
|
None
String updated in the repository |
|
None
String updated in the repository |
|
None
Automatically translated |
|
None
String updated in the repository |
|
Key
adventures->blackjack->levels->17->story_textLabels
Automatically translatedFlags
ignore-double-space, ignore-ellipsis, ignore-inconsistent, ignore-long-untranslated, ignore-same, ignore-translated, placeholders:r"`([^`\n\r]+)`|## ", python-brace-format
The Ace is worth either 1 or 11 points (you can choose). The dealer, your opponent, also gets two cards.
If you want, you can get another card, and its points will be added to your total. The dealer can also choose to take another card.
But be careful not to get more than 21 points, because if you do, you lose!
The player who gets closest to 21, without going over it, wins!
### Exercise
In this adventure we code the first part of our Blackjack game. We'll create a function to calculate how many points a card is worth.
***Set the variables***
Start by making a list of all the cards, from 2 to Ace. Next make a list of the face cards, so Jack, Queen and King. Then pick a random card from the list of cards to be card_1.
***Create a function to calculate the points***
Create a function that calculates how many points a card is worth.
All the face cards are worth 10 points, the Ace is worth 11 and all the other cards are worth their numeral.
Return the variable `points` at the end of the function.
***Test the function***
Test if your function is working properly. Finish the first print command by filling in which card you've drawn. Then finish the second line by calling the function with card_1.
Run the code a couple of times. Are you happy with the results? Great! Then you can remove the testing part and move on the the next tab!
The Ace is worth either 1 or 11 points (you can choose). The dealer, your opponent, also gets two cards.
If you want, you can get another card, and its points will be added to your total. The dealer can also choose to take another card.
But be careful not to get more than 21 points, because if you do, you lose!
The player who gets closest to 21, without going over it, wins!
Have fun!
### Exercise
This code works fine, but it's awfully long and cumbersome. Can you shorten the code by using functions?In this adventure we code the first part of our Blackjack game. We'll create a function to calculate how many points a card is worth.***Set the variables***
Start by making a list of all the cards, from 2 to Ace. Next make a list of the face cards, so Jack, Queen and King. Then pick a random card from the list of cards to be card_1.
***Create a function to calculate the points***
Create a function that calculates how many points a card is worth.
All the face cards are worth 10 points, the Ace is worth 11 and all the other cards are worth their numeral.
Return the variable `points` at the end of the function.
***Test the function***
Test if your function is working properly. Finish the first print command by filling in which card you've drawn. Then finish the second line by calling the function with card_1.
Run the code a couple of times. Are you happy with the results? Great! Then you can remove the testing part and move on the the next tab!