Answer to Question #314354 in Python for Kenjie

Question #314354

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-19T12:25:15-0400
import random


def roll(name, diceNum):
    if diceNum == 0:
        diceNum = 1
    
    f =  random.randint(1, abs(diceNum))
    t =  random.randint(1, abs(diceNum))
    r = 0
    d = ""
    if t == f : 
        r = (t+f)*2
        d = "DOUBLELD "
    else:
        r = t+f
    return r, print(name, " rolled ", f, " and ", t, " reslting in ",d, r)
    


print("Enter the amount for dice sides")
Dice_Sides = input()
try:
    int(Dice_Sides)
except:
    Dice_Sides = 1 


one =  roll("Player", Dice_Sides)
two = roll("Computer", Dice_Sides)
if one > two :
    print("PLAYER WINS!")
elif two > one:
    print("COMPUTER WINS!")
else:
    print("DRAW!")


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