Answer to Question #314273 in Python for Dhea M. Maddela

Question #314273

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 as is 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.


I need the code to have an output stated above.


1
Expert's answer
2022-03-19T03:58:57-0400
import random

print("Rolling Player dice")
playerD1 = random.randint(1, 6)
print("Die 1 outcome:", playerD1)
playerD2 = random.randint(1, 6)
print("Die 2 outcome:", playerD2)

playerSum = playerD1 + playerD2

if playerD1 == playerD2:
    playerSum *= 2

print("Sum:", playerSum)
print()

print("Rolling CPU dice")
cpuD1 = random.randint(1, 6)
print("Die 1 outcome:", cpuD1)
cpuD2 = random.randint(1, 6)
print("Die 2 outcome:", cpuD2)

cpuSum = cpuD1 + cpuD2

if cpuD1 == cpuD2:
    cpuSum *= 2

print("Sum:", cpuSum)
print()

if playerSum > cpuSum:
    print("Player Wins!")
elif playerSum < cpuSum:
    print("CPU Wins!")
else:
    print("It's a tie!")

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