Build a Dice Roll Generator Game using Python

Coding Wall
CodingWall
Published in
1 min readFeb 26, 2023

In this article, we will create a simple Dice Roll Generator game using Python’s random module. It is a built-in module that can be used to generate random numbers.

random.randint(): Returns a random number between a given range.

We will ask the user to input any number between 2 to 10. This number tells us the count of dice the user wants to use. I have kept the limit to 10, but you can increase it if you want. Then, we will generate random numbers for dice, store them in a list & print their sum & product.

import random

num = int(input('Enter any no between 2 & 10\t'))

if num<=10:
pass
else:
print('Please enter a number between 2 & 10')
num = int(input('Enter any no between 2 & 10\t'))
if num>10:
print('Sorry! Please try again!')

if num<=10:
print(f'You entered {num}')
dice = []
sum = 0
product = 1
for i in range(num):
dice1 = random.randint(1,6)
dice.append(dice1)
print(f'Numbers on dice: {dice}')
for i in range(num):
sum = sum+dice[i]
print(f'Sum: {sum}')
for i in range(num):
product = product*dice[i]
print(f'Product: {product}')

If this article was useful to you, share it to help others find it.

HAPPY LEARNING! HAPPY CODING!

--

--