Roll a Dice

Lesson Progress
0% Complete

This program will generate a random number (between 1-6), just like a dice.
For using the random library of python, we must include or import it first-hand.

The randint – method will generate a number every time, but for that we must provide the range of desired output.(i.e. range from 1 to 6.)

# importing the random module / library so that we can use the predefined methods
import random
# a dice contains 6 choices as output
# range of 6 is passed inside randint method
roll_dice = random.randint(1,6)
# a random number is stored inside the roll_dice variable
print(f'Result of Rolling a Dice\n{roll_dice}')