Build a Dice-Rolling Application With Python

Build a Dice-Rolling Application With Python

by Leodanis Pozo Ramos Feb 02, 2025 basics projects

In this tutorial, you’ll learn how to create a Python dice roll simulator. The tutorial guides you through building a text-based user interface (TUI) application that simulates rolling dice using Python’s random module. You’ll learn to gather and validate user input, use random.randint() for dice rolling, and display results with ASCII art.

By the end of this tutorial, you’ll understand that:

  • To simulate dice-rolling events, you can use random.randint() .
  • To get the user’s input, you use the built-in input() function.
  • To display dice in Python, you generate ASCII art representations of dice faces and use print().
  • To manipulate strings, you use methods such as .center() and .join().

Building small projects, like a text-based user interface (TUI) dice-rolling application, will help you level up your Python programming skills. You’ll learn how to gather and validate the user’s input, import code from modules and packages, write functions, use for loops and conditionals, and neatly display output by using strings and the print() function.

Click the link below to download the entire code for this dice-rolling application and follow along while you build the project yourself:

Demo

In this step-by-step project, you’ll build an application that runs dice-rolling simulations. The app will be able to roll up to six dice, with each die having six faces. After every roll, the application will generate an ASCII diagram of dice faces and display it on the screen. The following video demonstrates how the app works:

Python Dice Roll App Demo Video

When you run your dice-rolling simulator app, you get a prompt asking for the number of dice you want to roll. Once you provide a valid integer from 1 to 6, inclusive, then the application simulates the rolling event and displays a diagram of dice faces on the screen.

Project Overview

Your dice-rolling simulator app will have a minimal yet user-friendly text-based user interface (TUI), which will allow you to specify the number of six-sided dice that you’d like to roll. You’ll use this TUI to roll the dice at home without having to fly to Las Vegas.

Here’s a description of how the app will work internally:

Tasks to Run Tools to Use Code to Write
Prompt the user to choose how many six-sided dice to roll, then read the user’s input Python’s built-in input() function A call to input() with appropriate arguments
Parse and validate the user’s input String methods, comparison operators, and conditional statements A user-defined function called parse_input()
Run the dice-rolling simulation Python’s random module, specifically the randint() function A user-defined function called roll_dice()
Generate an ASCII diagram with the resulting dice faces Loops, list.append(), and str.join() A user-defined function called generate_dice_faces_diagram()
Display the diagram of dice faces on the screen Python’s built-in print() function A call to print() with appropriate arguments

Keeping these internal workings in mind, you’ll code three custom functions to provide the app’s main features and functionalities. These functions will define your code’s public API, which you’ll call to bring the app to life.

To organize the code of your dice-rolling simulator project, you’ll create a single file called dice.py in a directory of your choice in your file system. Go ahead and create the file to get started!

Prerequisites

You should be comfortable with the following concepts and skills before you start building this dice-rolling simulation project:

If you don’t have all of the prerequisite knowledge before starting this coding adventure, then that’s okay! You might learn more by going ahead and getting started! You can always stop and review the resources linked here if you get stuck.

Step 1: Code the TUI of Your Python Dice-Rolling App

In this step, you’ll write the required code to ask for the user’s input of how many dice they want to roll in the simulation. You’ll also code a Python function that takes the user’s input, validates it, and returns it as an integer number if the validation was successful. Otherwise, the function will ask for the user’s input again.

To download the code for this step, click the following link and navigate to the source_code_step_1/ folder:

Take the User’s Input at the Command Line

To get your hands dirty, you can start writing the code that interacts with the user. This code will provide the app’s text-based interface and will rely on input(). This built-in function reads the user input from the command line. Its prompt argument allows you to pass a description of what type of input you need.

Fire up your favorite editor or IDE and type the following code into your dice.py file:

Python dice.py
 1# ~~~ App's main code block ~~~
 2# 1. Get and validate user's input
 3num_dice_input = input("How many dice do you want to roll? [1-6] ")
 4num_dice = parse_input(num_dice_input)

Your call to input() on line 3 displays a prompt asking how many dice the user wants to roll. The number must fall in the interval from 1 to 6, inclusive, as the prompt suggests.

Line 4 calls parse_input() and stores the return value in num_dice. In the following section, you’ll implement this function.

Parse and Validate the User’s Input

The job of parse_input() is to take the user’s input as a string, check if it’s a valid integer number, and return it as a Python int object. Go ahead and add the following to your dice.py file, right before the app’s main code:

Python dice.py
 1def parse_input(input_string):
 2    """Return `input_string` as an integer between 1 and 6.
 3
 4    Check if `input_string` is an integer number between 1 and 6.
 5    If so, return an integer with the same value. Otherwise, tell
 6    the user to enter a valid number and quit the program.
 7    """
 8    if input_string.strip() in {"1", "2", "3", "4", "5", "6"}:
 9        return int(input_string)
10    else:
11        print("Please enter a number from 1 to 6.")
12        raise SystemExit(1)
13
14# ~~~ App's main code block ~~~
15# ...

Here’s how this code works line by line:

  • Line 1 defines parse_input(), which takes the input string as an argument.

  • Lines 2 to 7 provide the function’s docstring. Including an informative and well-formatted docstring in your functions is a best practice in Python programming because docstrings allow you to document your code.

  • Line 8 checks if the user input is a valid value for the number of dice to roll. The call to .strip() removes any unwanted spaces around the input string. The in operator checks if the input falls within the set of allowed numbers of dice to roll. In this case, you use a set because membership tests in this Python data structure are quite efficient.

  • Line 9 converts the input into an integer number and returns it to the caller.

  • Line 11 prints a message to the screen to alert the user of invalid input, if applicable.

  • Line 12 exits the app with a SystemExit exception and a status code of 1 to signal that something went wrong.

With parse_input(), you process and validate the user’s input at the command line. Validating any input that comes directly from the user or any untrusted sources is key for your application to work reliably and securely.

Now that you have a user-friendly TUI and a proper input validation mechanism, you need to make sure that these functionalities work correctly. That’s what you’ll do in the following section.

Try Out the Dice-Rolling App’s TUI

To try out the code that you’ve written so far, open a command-line window and run your dice.py script:

Shell
$ python dice.py
How many dice do you want to roll? [1-6] 3

$ python dice.py
How many dice do you want to roll? [1-6] 7
Please enter a number from 1 to 6.

If you enter an integer number from 1 to 6, then the code doesn’t display a message. On the other hand, if the input isn’t a valid integer number or falls outside the target interval, then you get a message telling you that an integer number from 1 to 6 is required.

Up to this point, you’ve successfully written code to request and parse the user’s input at the command line. This code provides the application’s TUI, which is based on the built-in input() function. You’ve also coded a function to validate the user’s input and return it as an integer number. Now, it’s time to roll the dice!

Step 2: Simulate the Rolling of Six-Sided Dice in Python

Your dice-rolling app now provides a TUI to take the user’s input and process it. Great! To continue building the application’s main functionality, you’ll write the roll_dice() function, which will allow you to simulate a dice-rolling event. This function will take the number of dice that the user wants to roll.

Python’s random module from the standard library provides the randint() function, which generates pseudo-random integer numbers in a given interval. You’ll take advantage of this function to simulate rolling dice.

To download the code for this step, click the following link and look inside the source_code_step_2/ folder:

Here’s the code that implements roll_dice():

Python dice.py
 1import random
 2
 3# ...
 4
 5def roll_dice(num_dice):
 6    """Return a list of integers with length `num_dice`.
 7
 8    Each integer in the returned list is a random number between
 9    1 and 6, inclusive.
10    """
11    roll_results = []
12    for _ in range(num_dice):
13        roll = random.randint(1, 6)
14        roll_results.append(roll)
15    return roll_results
16
17# ~~~ App's main code block ~~~
18# ...

In this code snippet, line 1 imports random into your current namespace. This import allows you to access the randint() function later. Here’s a breakdown of the rest of the code:

  • Line 5 defines roll_dice(), which takes an argument representing the number of dice to roll in a given call.

  • Lines 6 to 10 provide the function’s docstring.

  • Line 11 creates an empty list, roll_results, to store the results of the dice-rolling simulation.

  • Line 12 defines a for loop that iterates once for each die that the user wants to roll.

  • Line 13 calls randint() to generate a pseudo-random integer number from 1 to 6, inclusive. This call generates a single number on each iteration. This number represents the result of rolling a six-sided die.

  • Line 14 appends the current die-rolling result in roll_results.

  • Line 15 returns the list of dice-rolling simulation results.

To try out your newly created function, add the following lines of code to the end of your dice.py file:

Python dice.py
 1# ...
 2
 3# ~~~ App's main code block ~~~
 4# 1. Get and validate user's input
 5num_dice_input = input("How many dice do you want to roll? [1-6] ")
 6num_dice = parse_input(num_dice_input)
 7# 2. Roll the dice
 8roll_results = roll_dice(num_dice)
 9
10print(roll_results)  # Remove this line after testing the app

In this code, line 8 calls roll_dice() with num_dice as an argument. Line 10 calls print() to show the result as a list of numbers on your screen. Each number in the list represents the result for a single die. You can remove line 10 after testing your code.

Go ahead and run your app from the command line:

Shell
$ python dice.py
How many dice do you want to roll? [1-6] 5
[6, 1, 3, 6, 6]

$ python dice.py
How many dice do you want to roll? [1-6] 2
[2, 6]

The lists of results on your screen will be different because you’re generating your own pseudo-random numbers. In this example, you simulate the rolling of five and two dice, respectively. The value of each die is between 1 and 6 because you’re working with six-sided dice.

Now that you’ve written and tried out the code that simulates a dice-rolling event, it’s time to move on and provide your application with a flashy way to display these results. That’s what you’ll do in the next section.

Step 3: Generate and Display the ASCII Diagram of Dice Faces

At this point, your app already simulates the rolling of several dice and stores the results as a list of numbers. A list of numbers doesn’t look attractive from the user’s perspective, though. You need a fancier output so that your app looks professional.

In this section, you’ll write code to generate a diagram showing the faces of up to six dice. To do this, you’ll create a bit of ASCII art.

Click the link below to download the code for this step so that you can follow along with the project. You’ll find what you need in the source_code_step_3/ folder:

Set Up the Diagram of Dice Faces

Your dice-rolling simulator app needs a way to show the result of rolling the dice. To this end, you’ll use an ASCII diagram of dice faces that’ll show the result of rolling the desired number of six-sided dice. For example, after rolling four dice, the diagram will look something like this:

~~~~~~~~~~~~~~~~~~~ RESULTS ~~~~~~~~~~~~~~~~~~~
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│  ●   ●  │ │         │ │  ●      │ │  ●      │
│         │ │    ●    │ │    ●    │ │         │
│  ●   ●  │ │         │ │      ●  │ │      ●  │
└─────────┘ └─────────┘ └─────────┘ └─────────┘

Each die face in this diagram reflects the value that results from one iteration of the simulation. To start coding the functionality to build this diagram, you need to put together some ASCII art. Get back to your code editor and add the following:

Python dice.py
 1import random
 2
 3DICE_ART = {
 4    1: (
 5        "┌─────────┐",
 6        "│         │",
 7        "│    ●    │",
 8        "│         │",
 9        "└─────────┘",
10    ),
11    2: (
12        "┌─────────┐",
13        "│  ●      │",
14        "│         │",
15        "│      ●  │",
16        "└─────────┘",
17    ),
18    3: (
19        "┌─────────┐",
20        "│  ●      │",
21        "│    ●    │",
22        "│      ●  │",
23        "└─────────┘",
24    ),
25    4: (
26        "┌─────────┐",
27        "│  ●   ●  │",
28        "│         │",
29        "│  ●   ●  │",
30        "└─────────┘",
31    ),
32    5: (
33        "┌─────────┐",
34        "│  ●   ●  │",
35        "│    ●    │",
36        "│  ●   ●  │",
37        "└─────────┘",
38    ),
39    6: (
40        "┌─────────┐",
41        "│  ●   ●  │",
42        "│  ●   ●  │",
43        "│  ●   ●  │",
44        "└─────────┘",
45    ),
46}
47DIE_HEIGHT = len(DICE_ART[1])
48DIE_WIDTH = len(DICE_ART[1][0])
49DIE_FACE_SEPARATOR = " "
50
51# ...

In lines 3 to 46, you draw six dice faces using ASCII characters. You store the faces in DICE_ART, a dictionary that maps each face to its corresponding integer value.

Line 47 defines DIE_HEIGHT, which holds the number of rows a given face will occupy. In this example, each face takes up five rows. Similarly, line 48 defines DIE_WIDTH to hold the number of columns required to draw a die face. In this example, the width is 11 characters.

Finally, line 49 defines DIE_FACE_SEPARATOR, which holds a single space character. You’ll use all these constants to generate and display the ASCII diagram of dice faces for your application.

Generate the Diagram of Dice Faces

At this point, you’ve built the ASCII art for each die face. To put these pieces together into a final diagram representing the complete results of the dice-rolling simulation, you’ll write another custom function:

Python dice.py
 1# ...
 2
 3def generate_dice_faces_diagram(dice_values):
 4    """Return an ASCII diagram of dice faces from `dice_values`.
 5
 6    The string returned contains an ASCII representation of each die.
 7    For example, if `dice_values = [4, 1, 3, 2]` then the string
 8    returned looks like this:
 9
10    ~~~~~~~~~~~~~~~~~~~ RESULTS ~~~~~~~~~~~~~~~~~~~
11    ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
12    │  ●   ●  │ │         │ │  ●      │ │  ●      │
13    │         │ │    ●    │ │    ●    │ │         │
14    │  ●   ●  │ │         │ │      ●  │ │      ●  │
15    └─────────┘ └─────────┘ └─────────┘ └─────────┘
16    """
17    # Generate a list of dice faces from DICE_ART
18    dice_faces = []
19    for value in dice_values:
20        dice_faces.append(DICE_ART[value])
21
22    # Generate a list containing the dice faces rows
23    dice_faces_rows = []
24    for row_idx in range(DIE_HEIGHT):
25        row_components = []
26        for die in dice_faces:
27            row_components.append(die[row_idx])
28        row_string = DIE_FACE_SEPARATOR.join(row_components)
29        dice_faces_rows.append(row_string)
30
31    # Generate header with the word "RESULTS" centered
32    width = len(dice_faces_rows[0])
33    diagram_header = " RESULTS ".center(width, "~")
34
35    dice_faces_diagram = "\n".join([diagram_header] + dice_faces_rows)
36    return dice_faces_diagram
37
38# ~~~ App's main code block ~~~
39# ...

This function does the following:

  • Line 3 defines generate_dice_faces_diagram() with a single argument called dice_values. This argument will hold the list of dice-rolling integer values that results from calling roll_dice().

  • Lines 4 to 16 provide the function’s docstring.

  • Line 18 creates an empty list called dice_faces to store the dice faces corresponding to the input list of dice values. These dice faces will display in the final ASCII diagram.

  • Line 19 defines a for loop to iterate over the dice values.

  • Line 20 retrieves the die face corresponding to the current die value from DICE_ART and appends it to dice_faces.

  • Line 23 creates an empty list to hold the rows in the final dice faces diagram.

  • Line 24 defines a loop that iterates over indices from 0 to DIE_HEIGHT - 1. Each index represents the index of a given row in the dice faces diagram.

  • Line 25 defines row_components as an empty list to hold portions of the dice faces that will fill a given row.

  • Line 26 starts a nested for loop to iterate over the dice faces.

  • Line 27 stores each row component.

  • Line 28 joins the row components into a final row string, separating individual components with spaces.

  • Line 29 appends each row string to the list holding the rows that’ll shape the final diagram.

  • Line 32 creates a temporary variable to hold the width of the current dice faces diagram.

  • Line 33 creates a header showing the word RESULTS. To do so, it uses str.center() with the diagram’s width and the tilde symbol (~) as arguments.

  • Line 35 generates a string that holds the final dice faces diagram. The line feed character (\n) works as a row separator. The argument to .join() is a list of strings concatenating the diagram header and the strings (rows) that shape the dice faces.

  • Line 36 returns a ready-to-print dice faces diagram to the caller.

Wow! That was a lot! You’ll go back to this code and improve it to make it more manageable in just a bit. Before doing that, though, you’ll want to try out your application, so you need to finish writing its main code block.

Finish Up the App’s Main Code and Roll the Dice

With generate_dice_faces_diagram() in place, you can now finish writing the application’s main code, which will allow you to actually generate and display the diagram of dice faces on your screen. Go ahead and add the following lines of code to the end of dice.py:

Python dice.py
 1# ...
 2
 3# ~~~ App's main code block ~~~
 4# 1. Get and validate user's input
 5num_dice_input = input("How many dice do you want to roll? [1-6] ")
 6num_dice = parse_input(num_dice_input)
 7# 2. Roll the dice
 8roll_results = roll_dice(num_dice)
 9# 3. Generate the ASCII diagram of dice faces
10dice_face_diagram = generate_dice_faces_diagram(roll_results)
11# 4. Display the diagram
12print(f"\n{dice_face_diagram}")

Line 10 calls generate_dice_faces_diagram() with roll_results as an argument. This call builds and returns a diagram of dice faces that corresponds to the current dice-rolling results. Line 12 calls print() to display the diagram on the screen.

With this update, you can run the application again. Get back to your command line and execute the following command:

Shell
$ python dice.py
How many dice do you want to roll? [1-6] 5

~~~~~~~~~~~~~~~~~~~~~~~~~ RESULTS ~~~~~~~~~~~~~~~~~~~~~~~~~
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│  ●   ●  │ │  ●   ●  │ │  ●   ●  │ │  ●      │ │  ●   ●  │
│    ●    │ │  ●   ●  │ │  ●   ●  │ │    ●    │ │         │
│  ●   ●  │ │  ●   ●  │ │  ●   ●  │ │      ●  │ │  ●   ●  │
└─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘

Cool! Now your dice-rolling simulator app displays a nicely formatted ASCII diagram showing the result of the simulation event. That’s neat, isn’t it?

If you go back to the implementation of generate_dice_faces_diagram(), then you’ll note that it includes a few comments that point out what the corresponding portion of code is doing:

Python
def generate_dice_faces_diagram(dice_values):
    # ...
    # Generate a list of dice faces from DICE_ART
    dice_faces = []
    for value in dice_values:
        dice_faces.append(DICE_ART[value])

    # Generate a list containing the dice faces rows
    dice_faces_rows = []
    for row_idx in range(DIE_HEIGHT):
        row_components = []
        for die in dice_faces:
            row_components.append(die[row_idx])
        row_string = DIE_FACE_SEPARATOR.join(row_components)
        dice_faces_rows.append(row_string)

    # Generate header with the word "RESULTS" centered
    width = len(dice_faces_rows[0])
    diagram_header = " RESULTS ".center(width, "~")

    dice_faces_diagram = "\n".join([diagram_header] + dice_faces_rows)
    return dice_faces_diagram

This kind of comment often signals that your code would benefit from some refactoring. In the following section, you’ll use a popular refactoring technique that will help you clean up the code and make it more maintainable.

Step 4: Refactor the Code That Generates the Diagram of Dice Faces

Your generate_dice_faces_diagram() function requires explanatory comments because it performs several operations at a time, which violates the single-responsibility principle.

Roughly stated, this principle says that every function, class, or module should do only one thing. That way, changes in a given functionality won’t break the rest of the code. As a result, you’ll end up with a more robust and maintainable code.

To download the code for this step, click the link below, then check out the source_code_step_4/ folder:

There’s a refactoring technique called extract method that can help you improve your code by extracting functionality that can work independently. For example, you can extract the code from line 18 to 20 in the previous implementation of generate_dice_faces_diagram() and place it in a non-public helper function called _get_dice_faces():

Python
def _get_dice_faces(dice_values):
    dice_faces = []
    for value in dice_values:
        dice_faces.append(DICE_ART[value])
    return dice_faces

You can call _get_dice_faces() from generate_dice_faces_diagram() to get the implied functionality. By using this technique, you can fully refactor generate_dice_faces_diagram() to satisfy the single-responsibility principle.

Here’s a refactored version of generate_dice_faces_diagram() that takes advantage of _get_dice_faces() and implements another helper function called _generate_dice_faces_rows() to extract the functionality from line 23 to 29:

Python dice.py
# ...

def generate_dice_faces_diagram(dice_values):
    """Return an ASCII diagram of dice faces from `dice_values`.

    The string returned contains an ASCII representation of each die.
    For example, if `dice_values = [4, 1, 3, 2]` then the string
    returned looks like this:

    ~~~~~~~~~~~~~~~~~~~ RESULTS ~~~~~~~~~~~~~~~~~~~
    ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
    │  ●   ●  │ │         │ │  ●      │ │  ●      │
    │         │ │    ●    │ │    ●    │ │         │
    │  ●   ●  │ │         │ │      ●  │ │      ●  │
    └─────────┘ └─────────┘ └─────────┘ └─────────┘
    """
    dice_faces = _get_dice_faces(dice_values)
    dice_faces_rows = _generate_dice_faces_rows(dice_faces)

    # Generate header with the word "RESULTS" centered
    width = len(dice_faces_rows[0])
    diagram_header = " RESULTS ".center(width, "~")

    dice_faces_diagram = "\n".join([diagram_header] + dice_faces_rows)
    return dice_faces_diagram

def _get_dice_faces(dice_values):
    dice_faces = []
    for value in dice_values:
        dice_faces.append(DICE_ART[value])
    return dice_faces

def _generate_dice_faces_rows(dice_faces):
    dice_faces_rows = []
    for row_idx in range(DIE_HEIGHT):
        row_components = []
        for die in dice_faces:
            row_components.append(die[row_idx])
        row_string = DIE_FACE_SEPARATOR.join(row_components)
        dice_faces_rows.append(row_string)
    return dice_faces_rows

# ~~~ App's main code block ~~~
# ...

The newly added helper functions extract functionality from the original function. Now each helper function has its own single responsibility. Helper functions also allow you to use readable and descriptive names, removing the need for explanatory comments.

Refactoring your code to get it into better shape is a great skill to have as a Python developer. To dig deeper into code refactoring, check out Refactoring Python Applications for Simplicity.

A fundamental idea behind code refactoring is that the modified code should work the same as the original code. To check this principle, go ahead and run your application again!

With that, you’ve completed your project! You’ve built a fully functional TUI application that allows you to simulate a dice-rolling event. Every time you run the application, you can simulate the rolling of up to six dice with six faces each. You’ll even get to see the resulting dice faces in a nice-looking ASCII diagram. Great job!

Conclusion

You’ve coded a fully functional project consisting of a text-based user interface application that simulates the rolling of six-sided dice in Python. With this project, you learned and practiced fundamental skills, such as gathering and validating the user’s input, importing code, writing functions, using loops and conditionals, and displaying nicely formatted output on-screen.

In this tutorial, you learned how to:

  • Use random.randint() to simulate the rolling of dice
  • Take the user’s input at the command line using the built-in input() function
  • Parse and validate the user’s input using several tools and techniques
  • Manipulate strings using methods, such as .center() and .join()

Additionally, you learned how to structure, organize, document, and run Python programs and scripts. With this knowledge, you’re better prepared to continue your coding journey with Python.

You can download the full code for this dice-rolling application by clicking the link below:

Frequently Asked Questions

Now that you have some experience with building a dice-rolling application in Python, you can use the questions and answers below to check your understanding and recap what you’ve learned.

These FAQs are related to the most important concepts you’ve covered in this tutorial. Click the Show/Hide toggle beside each question to reveal the answer.

You can get a random number in Python by using the random.randint() function to generate a random integer within a specified range.

You simulate rolling dice by calling random.randint(1, 6) from Python’s random module, which generates a random integer within a specified range, such as 1 to 6 for a six-sided die.

You can print dice in Python by generating an ASCII diagram of dice faces with using string manipulation methods like .join() and .center(), then displaying it with the print() function. Common characters for an ASCII diagram of dice are , , , , and .

Next Steps

Now that you’ve finished building your dice-rolling application, you can take the project a step further by adding new functionality. Adding new features by yourself will help you continue to learn exciting new coding concepts and techniques.

Here are some ideas to take your project to the next level:

  • Support for any number of dice: Modify the code so that you can roll any number of dice.
  • Support for dice with different numbers of faces: Add code to support not only six-sided dice but dice with any number of sides.

The first feature will require you to modify the code that processes the user’s input for the number of dice to roll. You’ll also need to modify the code that generates and displays the diagram of dice faces. For example, you can generate a diagram that displays the dice faces in several rows to avoid cluttering your screen with cramped output.

On the other hand, supporting dice with a different number of faces will demand that you tweak the code that simulates a dice-rolling event. You’ll also need to create new ASCII art for any dice with more than six faces.

Once you’re done with these new features, you can change gears and jump into other cool projects. Here are some great next steps for you to continue learning Python and building more complex projects:

🐍 Python Tricks 💌

Get a short & sweet Python Trick delivered to your inbox every couple of days. No spam ever. Unsubscribe any time. Curated by the Real Python team.

Python Tricks Dictionary Merge

About Leodanis Pozo Ramos

Leodanis is an industrial engineer who loves Python and software development. He's a self-taught Python developer with 6+ years of experience. He's an avid technical writer with a growing number of articles published on Real Python and other sites.

» More about Leodanis

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

Master Real-World Python Skills With Unlimited Access to Real Python

Locked learning resources

Join us and get access to thousands of tutorials, hands-on video courses, and a community of expert Pythonistas:

Level Up Your Python Skills »

Master Real-World Python Skills
With Unlimited Access to Real Python

Locked learning resources

Join us and get access to thousands of tutorials, hands-on video courses, and a community of expert Pythonistas:

Level Up Your Python Skills »

What Do You Think?

Rate this article:

What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment below and let us know.

Commenting Tips: The most useful comments are those written with the goal of learning from or helping out other students. Get tips for asking good questions and get answers to common questions in our support portal.


Looking for a real-time conversation? Visit the Real Python Community Chat or join the next “Office Hours” Live Q&A Session. Happy Pythoning!