Coding a dice on Python
Coding a dice on Python where the input is a random number only requires a few lines of code. Three to be exact. Below you will find the code that will give you a random number between 1 and 6.
import random roll_dice = random.randint(1, 6) print(roll_dice)
Anatomy of the code
The steps are straightforward:
Find the appropriate book(aka module) in the Python library. In this case random.
Use the import statement to take it out of the bookcase(aka library).
In the book (aka: module) of random, find the recipe (aka: function) on randint.
This is the recipe (aka: function):
Hmm, this describes the exact characteristic of a dice. Thus, we shall call this recipe (aka: function) roll_dice. As a dice only has 6 sides from 1 to 6, the ranges of a & b are given.
roll_dice = random.randint(1,6)
Print the recipe(aka:function) with the print() function