Answer to Question #314263 in Python for Harley

Question #314263

Simple Dice Game


Develop a Python application that will simulate a simple dice game by rolling two dice for the player as his bet followed by another roll of the two dice for the computer.


The mechanics is as follows:


1. If after the roll of the two dice, resulted to same number then the sum will be doubled.


2. If the value of each dice is different, then just get the sum of the values of each dice.


Who gets the highest value wins the game.

1
Expert's answer
2022-03-19T04:13:55-0400
import random


playerDie1=random.randint(1, 6)
playerDie2=random.randint(1, 6)


sumResultPlayer=playerDie1+playerDie2
if playerDie1==playerDie2:
    sumResultPlayer=sumResultPlayer*2


computerDie1=random.randint(1, 6)
computerDie2=random.randint(1, 6)
sumResultComputer=computerDie1+computerDie2
if computerDie1==computerDie2:
    sumResultComputer=sumResultComputer*2


if sumResultPlayer>sumResultComputer:
    print(f"Player gets the highest value {sumResultPlayer} wins the game.")
else:
    print(f"Computer gets the highest value {sumResultComputer} wins the game.")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS