Python 3.0 Blackjack (twenty-one) is a casino game played with cards. The goal o
ID: 3857584 • Letter: P
Question
Python 3.0
Blackjack (twenty-one) is a casino game played with cards. The goal of the game to draw cards that total as close to 21 points as possible without going over. All face cards count as 10 points, aces count as 1 or 11, and all other cards count their numeric value. The game is played against a dealer. The player tries to get closer to 21 (without going over) than the dealer. If the dealer busts (goes over 21) the player automatically wins (provided the player had not already busted). The dealer must always take cards according to a fixed set of rules. The dealer takes cards until he or she achieves a total of at least 17. If the dealer's hand contains an ace, it will be counted as 11 when that results in a total between 17 and 21 inclusive; otherwise, the ace is counted as 1. Write a program that simulates multiple games of blackjack and estimates the probability that the dealer will bust.
Explanation / Answer
def printIntro(): print("This program simulates a bunch of blackjack games.") def getInputs(): while True: n = eval(input("How many games should be simulated? ")) if n = 17: break if blackscore == 11 and (score >= 6 and score = 22: busts = busts + 1 else: holds = holds + 1 return holds, busts def gameOver(score): return score >= 22 or score >= 17 def printSummary(holds, busts): n = holds + busts print("Number of holds and busts: Holds: {0:0} Busts: {1:0}".format(holds, busts)) print("Percentage of holds and busts: Holds: {0:0.1%}".format(holds / n), end = " ") print("Busts: {0:0.1%}".format(busts / n)) def main(): printIntro() n = getInputs() score = simOneGame() holds, busts = simNGames(n) printSummary(holds, busts) if __name__ == "__main__": main()Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.