Dice Roll game with python programming language is easy to make and implement. And this is a very simple program where users can play and make game more easy.
So, Dice Roll game is a python programming language game where a random number is used. And using python as a programming language, you can easy build command line games.
- Python 2
- and random
So, Users can run this game through terminal. And He/she only have to type python filename.py
Therefore, this step ask a user to decide to continue or leave. Also, ask users to roll the dice with yes or no question.
Therefore, this step ask users if they want to try again. So, users have to type yes to continue to roll the dice. And after rolling a dice, random number is generated which are given above.
Therefore, this step is to end a game by typing no.
And system will ask if users want to continue and if they don’t want to then can type no. And this no statement will end a dice roll game.
Therefore Things to know
- You should install python 2.0 to run this game.
- And You should install any kind of IDE you are comfortable with python.
- So, I recommend you to use jupyter notebook.
- And you have to install time and random libraries.
- So, install it by: sudo pip install library name.
Therefore, the code looks like this.
min = 1
max = 6
print("=" * 34)
print("= Welcome to Roll the Dice Game. =")
print("=" * 34)
user_input = raw_input("\nRoll the dice? [Y/N] ")
print("Getting the values...\n")
dice1 = random.randint(min, max)
dice2 = random.randint(min, max)
print(" Dice #1 -> ", dice1)
print(" Dice #2 -> ", dice2)
dices_sum = dice1 + dice2
print(" The sum is", dices_sum)
if user_input == 'Y' or user_input == 'y':
while (user_input == 'Y' or user_input == 'y'):
user_input = raw_input("\nRoll the dice again? [Y/N] ")
elif user_input == 'N' or user_input == 'n':
So, you can copy this code and can easily run in your system.
Therefore this code can be very helpful to you.