Dice roll in Python

Jul 05, 2017
![](https://darryldias.me/content/images/2018/08/dice_roll_python.png)

Python is a fun language, the syntax is what feels so nice about it and how the indents are used to format the code, after using Jade and Sass, this comes very naturally to me.

I was learning about modules and found random to be a good place to start off, and turned out to be a very interesting internal module. To understand how it works I created a dice roll game, with just a few lines of code it would generate a random number, which in this context would be the side of the die, with a number.

As you can see it runs five times and generates random numbers.

"""
    Simple console game that returns random sides of a die 5 times
"""

# Importing random module
import random

# Adding inital attempt value
attempt = 1

# Run five times until attempt value equals 5
while attempt < 5:
    number = random.randint(1, 6)
    print("Your die roll is: " + str(number))
    attempt = attempt + 1


This was a great exercise and a very interesting way to learn Python.


If you like this content, please consider buying me a coffee.

Buy me a coffeeBuy me a coffee

You will get access to contributer exclusive resources and content.

Thank you!



Darryl Dias

I am a student, artist, and author currently living in Florida. My interests range from technology to arts. I am also interested in programming, writing

Analytics by GoSquared