Kalebu Jordan

Become a Pro Python Developer

Hello Guys on this tutorial you’re going to learn out how to build your own Roll dice simulator game in Python . which you can use to Play out with probability of numbers.

This is a beginner tutorial , therefore If you know basic concepts of python such as loop you can complete this tutorial.

Program overview

We will are going to use Python random module to generate random number of dice as you would have done by rolling it .

Python random module

In order to generate a simulated dice random number we use randint function where by we specify the min value and max value for our random generation

Example of Usage

```>>> import random
>>> random.randint(1, 6)
5
>>> random.randint(1, 6)
2```

Very simple indeed as shown above now , we just have to use the while loop to make our game continuous .

Roll dice simulator

```from random import randint

while True:
dice_random = randint(1, 6)
print('Print Rolled dice ', dice_random)
print('Should I generate again  ?')
again = int(input('1.Yes\n2.No\n\nEnter option here : '))
if again != 1:
break
print('Thanks for playing the game')   ```

Output :

```\$ python3 app.py
Print Rolled dice  1
Should I generate again  ?
1.Yes
2.No

Enter option here : 1
Print Rolled dice  6
Should I generate again  ?
1.Yes
2.No

Enter option here : 1
Print Rolled dice  3
Should I generate again  ?
1.Yes
2.No

Enter option here : 2
Thanks for playing the game```

Hope you find this post interesting , donâ€™t forget to subscribe to get more tutorials like this. To get the full code it on My Github

In case of any suggestion or comment , drop it on the comment box and I will reply to you immediately.