Monday, 19 October 2020

How to make a Dice Rolling Simulator using Python ? [ Source code included ]

 Snake and Ladder is a very popular game. We all are familiar with the dice that we use in this game. Here I am explaining a simple program that simulates the dice. I will be using random() function in python to implement this feature. 


 

The random module has so many functionalities and features. Here we will be using the random integer generation feature of the random module.

First lets get the simple program ready. 

import random
dice_value = random.randint(1,6)
print(dice_value)

The random.randint() function is the core logic in this function. The arguments 1 and 6 are the lower and upper limits of the random integer values. The function will return values between both these numbers including these numbers. 

Now let us try to give some more look and feel to the program. I have added some more lines of code to improve usability. This will give a visual effect also.



If you want a more advanced dice simulator, let us modify the program further to with a Graphical User Interface. We will use TKinter package in python to implement this simple user interface.

No comments:

Post a Comment

How to check the memory utilization of cluster nodes in a Kubernetes Cluster ?

 The memory and CPU utilization of a Kubernetes cluster can be checked by using the following command. kubectl top nodes The above command...