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.
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!")
Comments
Leave a comment