Learn to Code via Tutorials on Repl.it!

← Back to all posts
Die roll! (Python)
KyleWatson3 (0)

Hello everyone this is how to make a die roller in 🐍 🐍 Python !🐍 🐍

#Lets get started!
So first we’re gonna need randint so type this in a python repl:
from random import randint

Second, we are going to ask the user the size of the die:
sizeOfDie = input(“How many sides is the die?”)

And then we print the “roll”:
print(“Die roll: \n”) dieRoll = randint(1, sizeOfDie) print(dieRoll)

Bye y’all! Hope you enjoyed!

KyleWatson3 (0)

So the full (readable) extended version of it is:

from random import randint
sizeOfDie = int(input(“How many sides do you want the die to have?”))
dieRoll = randint(1, sizeOfDie)
print(“Die Roll:\n”)
IntellectualGuy (822)

This can be done in way less lines of code, here's my take

from random import randint;print("Die roll: \n\n {}".format(randint(1, int(input("How many sides do you want the die to have?")))))
KyleWatson3 (0)

@IntellectualGuy Yes that is a faster way but i did that for readability