Like the title suggests, this project involves writing a program that simulates rolling dice. When the program runs, it will randomly choose a number between 1 and 6. (Or whatever other integers you prefer — the number of sides on the die is up to you.) The program will print what that number is. It should then ask you if you’d like to roll again. Include tests for this program.
Asked
Active
Viewed 1,106 times
-3
-
SO is not a code factory. Please show what you've tried and describe exactly where you're stuck. – glibdud May 02 '19 at 19:40
-
your question is already answered in another [stackoverflow post](https://stackoverflow.com/questions/44008489/dice-rolling-simulator-in-python) – Suneel Kingrani May 02 '19 at 19:43
-
I just added another way of doing it which has not yet been done – Timm Ndirangu May 02 '19 at 19:50
-
Looks like a homework problem. – Doc May 02 '19 at 20:25
-
Possible duplicate of [Dice rolling simulator in Python](https://stackoverflow.com/questions/44008489/dice-rolling-simulator-in-python) – Doc May 02 '19 at 20:28
1 Answers
-1
First, you will have to import a 'random' number using the 'random' number module. So the randint is a function which basically stands for Random Integer. THen you will define your functions and pass the range of numbers from which the random number will come from (0,6). So repeat=True basically helps you to play the game another more time while the .lower will convert the uppercase to the lower case in that one can choose to play the game while the caps lock is on or off.
#Dice Rolling Simulator
#dice.py
from random import randint
def rand():
return randint(0,6)
repeat = True
while repeat:
print("You rolled",rand())
print("Do you want to roll again?")
repeat = ("y" or "yes") in input().lower()
print("Game Over")

Timm Ndirangu
- 1
- 5