How to make a text - based dice roller in python
Intro
Hello everyone welcome to my another post, in this post as you read the title I am going to tell you how to make a Text-Based Dice roller in python
Required modules
random
numpy
Uses of modules
random : We will use this module to display random numbers from 1 - 6
numpy : We will use this to create arrays
Let's Code
Importing the modules
from numpy import random
Making a function which will choose a random number between 1 - 6 and will print it
def dice():
random_int = random.choice([1, 2, 3, 4, 5, 6])
print("The number is: \n" + str(random_int))
dice()
Writing the code to ask user if he/she wants to continue
ask = True
while (ask == True):
print("Enter Yes or y to roll dice again \n")
conti = input("Do you want to continue? \n")
if conti == "yes":
dice()
elif conti == "y":
dice()
else:
exit(dice())
With this we have completed our text based dice roller in python. I hope you all enjoyed this post. Feel free to ask questions in the comments section.
Thanks For Reading