Dice Roll game with Python

Introduction

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.

Technologies used

  • Python 2
  • Sublime
  • Jupyter
  • Anaconda

Libraries used

  • time
  • and random

Step1

So, Users can run this game through terminal. And He/she only have to type python filename.py

step 2: welcome to roll the dice game

Therefore, this step ask a user to decide to continue or leave. Also, ask users to roll the dice with yes or no question.

Rolling a dice

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.

step4: end a dice game

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

  1. You should install python 2.0 to run this game.
  2. And You should install any kind of IDE you are comfortable with python.
  3. So, I recommend you to use jupyter notebook.
  4. And you have to install time and random libraries.
  5. So, install it by: sudo pip install library name.

Therefore, the code looks like this.

import time
import random

min = 1
max = 6

print("=" * 34)
print("= Welcome to Roll the Dice Game. =")
print("=" * 34)

user_input = raw_input("\nRoll the dice? [Y/N] ")

def dice_roll():
time.sleep(1)
print("\nRolling dices...")
time.sleep(1)
print("Getting the values...\n")
time.sleep(1)
dice1 = random.randint(min, max)
dice2 = random.randint(min, max)
print(" Dice #1 -> ", dice1)
print(" Dice #2 -> ", dice2)
time.sleep(1)
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'):
dice_roll()
user_input = raw_input("\nRoll the dice again? [Y/N] ")

elif user_input == 'N' or user_input == 'n':
print("Exiting")

else:
print("Invalid Input!")

So, you can copy this code and can easily run in your system.

Therefore this code can be very helpful to you.

0 0 vote
Article Rating

You may also like...

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x