Dice Game Simulation Using Python With Random Module
create a file dicegame.py
Installation :
$ pip install random
# how to create a dice game simulationusing python with random module in codepythonic
import random
player1_score = 0
player2_score = 0
for i in range(1,4):
print("=====ROUND -{} ===== ". format(i))
player1_input = input ("Press Enter The key To Roll The Dice : ")
player1_value = random.randint(1,6)
print (player1_value)
player2_input = input ("Press Enter The Key Name To Roll The Dice : ")
player2_value = random.randint(1,6)
print (player2_value)
if player1_value > player2_value :
print("Player 1 Win This Round ")
player1_score += 1
elif player1_value < player2_value :
print("Player 2 Win This Round ")
player2_score += 1
else:
print ("This Round Is Draw ")
if player1_value > player2_value :
print("Player 1 Wining Time ", player1_score)
player1_score += 1
elif player1_value < player2_value :
print("Player 2 Wining Time ", player2_score)
player2_score += 1
print ( "***Battle Over***")
Run Program :
python dicegame.py
Output
=====ROUND -1 =====
Press Enter The key To Roll The Dice :
6
Press Enter The Key To Roll The Dice :
4
Player 1 Win This Round
=====ROUND -2 =====
Press Enter The key To Roll The Dice :
3
Press Enter The Key To Roll The Dice :
4
Player 2 Win This Round
=====ROUND -3 =====
Press Enter The key To Roll The Dice :
1
Press Enter The Key To Roll The Dice :
3
Player 2 Win This Round
Player 2 Wining Time 2
***Battle Over***