2) Blackjack Dice. Write a program (called q2.p) to simulate the game of Blackja
ID: 3847149 • Letter: 2
Question
2) Blackjack Dice. Write a program (called q2.p) to simulate the game of Blackjack Dice. Blackjack Dice is based on two 11-sided dice, where each die represents the numbers from 1 to 11. The objective of this game is to roll 21. If you go over, it's considered a bust and you lose. Your score (without going over 21) must beat the dealer or you lose. Rules for the Player. The player begins by rolling the dice and the program adds their corresponding numbers. After the initial roll of the two dice, a player may choose to roll a single die as many times as they wish, adding the resulting number from each roll to their total. If the total exceeds 21, the dealer wins. If the player gets 21 after the first roll, this is considered Blackjack and leads to an automatic win. Rules for the Dealer. The dealer begins by rolling two dice and adds the numbers to get a total. The dealer continues rolling the dice until it reaches a total greater thanExplanation / Answer
I have gone through all your requirement which basically means to generate the Total score at the end of the game.
Eventually, I have developed the code using all those four functions such as roll_dice(), player(), dealer() & main(). I have added the code here, I explained the use of functions in a easy way.
Program:
from random import randomrange
def main():
introStruct()
n = dealer()
x = roll_die(n)
printResult(x,n)
def introStruct():
print('The program is about to start')
print('Possibility of total score result ')
def dealer():
n = eval(input('************** DEALERS TURN ************'))
return n
def roll_die(rounds):
win = 0
for i in range(rounds):
init = player()
if init == 'win': win = win+1
elif (type(init)) == int:
final = pointRoller(init)
if final == 'win': win = win+1
return win
def player():
x = dice()
if x == 7 or x == 11:
status = 'win'
elif x ==2 or x ==3 or x ==12:
status = 'lose'
else:
status = x
x = eval(input('************** YOUR TURN ************'))
return status
def pointRoller(point):
x = 0
while not pointChecker(x,point):
x = dice()
if x == point:
status = 'win'
elif x == 7:
status = 'lose'
return status
def pointChecker(x,point):
return x == 7 or x == point
def dice():
return randomrange(1,7)+randomrange(1,7)
def printResult(win,rounds):
print('==========================================')
print(' Play Assumed:',rounds)
print('Total Scores:',win)
print(' The Probability of Total Score is: {:0.2}'.format(win/rounds))
if __name__ == '__main__': main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.