Advertisement
Taximaniac

Simple Dice Roller example v0.0.2 (Refactored)

Feb 12th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. # import modules
  2. import time
  3. import random
  4. import os
  5.  
  6.  
  7. def display_rolling_dice_message():
  8.     dot = ""
  9.     for _ in range(23):
  10.         if len(dot) >= 5:
  11.             dot = ""
  12.         else:
  13.             dot += "."
  14.         os.system("cls")
  15.         print(f"Rolling Dices, Please Wait{dot}")
  16.         time.sleep(0.1)
  17.  
  18.  
  19. # make dice
  20. dice = list(range(1, 6))
  21.  
  22. # Make a empty list to hold value of rolled dices
  23. picked = []
  24.  
  25. # loop 5 times and pick up a random number from dice
  26. for _ in range(1, 6):
  27.     picked.append(random.choice(dice))
  28.  
  29. # display and animate rolling message
  30. display_rolling_dice_message()
  31.  
  32. # clear the console for new message
  33. os.system("cls")
  34.  
  35. # print the result
  36. print("Your dice roll ended up with:")
  37. print("--------------------------")
  38. print("| D1 | D2 | D3 | D4 | D5 |")
  39. print("--------------------------")
  40. print(f"|  {picked[0]} |  {picked[1]} |  {picked[2]} |  {picked[3]} |  {picked[4]} |")
  41. print("--------------------------")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement