id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

david.white@denison.edu cs111fall2019 > blackjack
prev  |  next  |  chance

A player wins at the card game blackjack if the total value of his or her cards is no more than 21, and if either this total is more than the dealer's total, or if the dealer exceeds 21. (To be clear, a player "busts" and thereby loses whenever their total is over 21, and loses when the dealer does not bust and has a total that is equal or higher.) Write the function blackjack(player_cards, dealer_cards) which returns True if the player wins. The player_cards is represented as a list of numbers in the range 1 to 10 (as is the dealer_cards) However, there is a complication: an ace, represented as a 1, can be counted as either 1 point or 11 points, whichever is more advantageous. So if you have the list of cards [1, 4], you can count that as either 5 points or 15 points; 15 is better, so use that. If you have [1, 4, 8], that can be either 13 or 23 points; 23 would be a bust, so 13 is better, so use that.


blackjack([10, 10], [10, 6]) → True
blackjack([10, 10], [10, 3, 9]) → True
blackjack([1, 1, 1, 1, 7], [10, 10]) → True

...Save, Compile, Run (ctrl-enter)

def blackjack(player_cards, dealer_cards):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 200 Post-solution available

Copyright Nick Parlante 2017 - privacy