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.
No comments:
Post a Comment