In this article we will create a classic rolling dice simulator with the help of basic Python knowledge. Here we will be using the random module since we randomize the dice simulator for random outputs.
Function used:
1) random.randint(): This function generates a random number in the given range.
Below is the implementation.
import random x = "y" while x == "y": # Gnenerates a random number # between 1 and 6 (including # both 1 and 6) no = random.randint(1,6) if no == 1: print("[-----]") print("[ ]") print("[ 0 ]") print("[ ]") print("[-----]") if no == 2: print("[-----]") print("[ 0 ]") print("[ ]") print("[ 0 ]") print("[-----]") if no == 3: print("[-----]") print("[ ]") print("[0 0 0]") print("[ ]") print("[-----]") if no == 4: print("[-----]") print("[0 0]") print("[ ]") print("[0 0]") print("[-----]") if no == 5: print("[-----]") print("[0 0]") print("[ 0 ]") print("[0 0]") print("[-----]") if no == 6: print("[-----]") print("[0 0 0]") print("[ ]") print("[0 0 0]") print("[-----]") x=input("press y to roll again and n to exit:") print("\n") |
chevron_right
filter_none
Output:

Recommended Posts:
- Multitape Nondeterministic Turing Machine simulator
- Python | Pandas Series.rolling()
- Python | Pandas dataframe.rolling()
- Reusable piece of python functionality for wrapping arbitrary blocks of code : Python Context Managers
- How to Convert String to Integer in Pandas DataFrame?
- Additive Secret Sharing and Share Proactivization - Using Python
- Common Operations on Fuzzy Set with Example and Code
- Build a COVID19 Vaccine Tracker Using Python
- String manipulations in Pandas DataFrame
- Missing data imputation with fancyimpute
- Add column names to dataframe in Pandas
- Concatenate two columns of Pandas dataframe
- How to plot a dataframe using Pandas?
- Fastest way to Convert Integers to Strings in Pandas DataFrame
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

