How to Create a Dice Roller App in Terminal Console using Python

In this tutorial, we will create a "How to Create a Dice Roller App in Terminal Console using Python". We will break down the basics of this program for creating a dice roller. Our goal is to understand the concept behind this program and learn the proper coding to develop it. I will provide a sample program to demonstrate the actual coding of this tutorial.

This topic is simple and easy to understand; just follow the instructions I provide, and you can also do it yourself with ease. The program I will show is a simple that will make our dice roll a number. I will do my best to provide you with the easiest method of creating this program, called "Dice Roller". So, let's start with the coding.

Getting Started:

First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python

Creating Main Function

This is the main function of the application. The following code will display a simple GUI in terminal console of Dice Roller. To do this, simply copy and paste these blocks of code into the IDLE text editor.
  1. import random
  3. print("\n\n=========== Dice Roller App =========== \n")
  4. x = 'y'
  5. while x == 'y':
  6. n = random.randint(1, 6)
  8. if n == 1:
  9. print("-----------")
  10. print("| |")
  11. print("| O |")
  12. print("| |")
  13. print("-----------")
  15. elif n==2:
  16. print("-----------")
  17. print("| O |")
  18. print("| |")
  19. print("| O |")
  20. print("-----------")
  22. elif n==3:
  23. print("-----------")
  24. print("| O |")
  25. print("| O |")
  26. print("| O |")
  27. print("-----------")
  29. elif n==4:
  30. print("-----------")
  31. print("| O O |")
  32. print("| |")
  33. print("| O O |")
  34. print("-----------")
  36. elif n==5:
  37. print("-----------")
  38. print("| O O |")
  39. print("| O |")
  40. print("| O O |")
  41. print("-----------")
  43. elif n==6:
  44. print("-----------")
  45. print("| O O |")
  46. print("| O O |")
  47. print("| O O |")
  48. print("-----------")
  50. x = input("Press 'y' to input Again: ")

In this code, we imported a module called "random"; this library is responsible for randomizing the entry index. Next, we enclosed the code with a while loop to keep the program running until it meets a certain condition. Lastly, we drew several objects that represent the dice numbers along with an if statement.


The How to Create a Dice Roller App in Terminal Console using Python source code that I provide can be download below. Please kindly click the download button.

There you have it we successfully created How to Create a Dice Roller App in Terminal Console using Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for Python Language

Python Tutorials

Add new comment