Advertisement
Taximaniac

Simple Dice Roller example v0.0.3 (Refactored)

Feb 13th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. # import modules
  2. import time
  3. import random
  4. import os
  5.  
  6.  
  7. def throw_dice() -> int:
  8.     """
  9.    A function that represent a six side dice that picks a random number
  10.    from a list of 6 numbers
  11.    :return: int
  12.    """
  13.     return random.choice([1, 2, 3, 4, 5, 6])
  14.  
  15.  
  16. def display_rolling_dice_message():
  17.     """a function to display a animated message"""
  18.     dots = [".", "..", "...", "....", "....."]
  19.     for _ in range(3):
  20.         for num in range(0, 5):
  21.             os.system("cls")
  22.             print(f"Rolling Dices, Please Wait{dots[num]}")
  23.             time.sleep(0.1)
  24.  
  25.  
  26. # display and animate rolling message
  27. display_rolling_dice_message()
  28.  
  29. # clear the console for new message
  30. os.system("cls")
  31.  
  32. # print the result
  33. print("Your dice roll ended up with:")
  34. print("--------------------------")
  35. print("| D1 | D2 | D3 | D4 | D5 |")
  36. print("--------------------------")
  37. print(f"|  {throw_dice()} |  {throw_dice()} |  {throw_dice()} |  {throw_dice()} |  {throw_dice()} |")
  38. print("--------------------------")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement