A Dice is one of the most important part of games like Snake and Ladders or Ludo. Dice Simulation is using the concepts of random module to roll a dice and print output either 1,2,3,4,5 or 6. Hence we import the random module and use the randint function to print any number between 1 and 6.

### Source Code:-

``````import random
print("THE NUMBER IS : ",random.randint(1,6))``````

Now we use the function concept from the previous posts and then we define a function called Dice_Simulator. and we return the number generated

``````import random
def Dice_Simulator():
Dice_Number=random.randint(1,6)
return Dice_Number
print("THE NUMBER IS : ",Dice_Simulator())
``````

To make it more personalized we give an option to the user to get another chance by printing yes or quit if something else is typed. We use the lower function so that it is user friendly and he doesn’t have to worry to print it in any case.

``````import random
def Dice_Simulator():
ch="yes"
while ch=="yes":
Dice_Number=random.randint(1,6)
print("THE NUMBER IS : ",Dice_Number)
ch1=input("ENTER YES IF YOU WANT TO CONTINUE : ")
ch=ch1.lower()
Dice_Simulator()``````

Now we give the user another chance if 6 is the first output.we use an is condition for that

``````import random
def Dice_Simulator():
ch="yes"
while ch=="yes":
Dice_Number=random.randint(1,6)
print("THE NUMBER IS : ",Dice_Number)
if Dice_Number==6:
print("YOU GOT 6 YOU ANOTHER CHANCE : ",random.randint(1,5))
ch1=input("ENTER YES IF YOU WANT TO CONTINUE : ")
ch=ch1.lower()
Dice_Simulator()``````

Now we use the if function to check the number on the dice and then display a virtual dice using | , \ , 0 and _

``````import random
def Dice_Simulator():
ch="yes"
while ch=="yes":
Dice_Number=random.randint(1,6)
print("THE NUMBER IS : ",Dice_Number)
if Dice_Number==1:
print(" _____")
print("|     |")
print("|  0  |")
print("|_____|")
if Dice_Number==2:
print(" ______")
print("|0     |")
print("|      |")
print("|_____0|")
if Dice_Number==3:
print(" _______")
print("|0      |")
print("|   0   |")
print("|______0|")
if Dice_Number==4:
print(" _______")
print("|0     0|")
print("|       |")
print("|0_____0|")
if Dice_Number==5:
print(" _______")
print("|0     0|")
print("|   0   |")
print("|0_____0|")
if Dice_Number==6:
print(" _______")
print("|0     0|")
print("|0     0|")
print("|0_____0|")
print("      ")
ch1=input("ENTER YES IF YOU WANT TO CONTINUE : ")
ch=ch1.lower()
Dice_Simulator() ``````

Visits: 337