Advertisement
kingtigermusic

dice roller

Jun 14th, 2024
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | Source Code | 0 0
  1. import time
  2. from numpy import random
  3. import sys
  4.  
  5. def dice(amount = 1, sides = 20):
  6.     if amount >= 1 and amount <= 10 and type(amount) is int:
  7.         if sides >= 2 and sides <= 100 and type(sides) is int:
  8.             thinking()
  9.             print(f"You rolled {amount} d{sides} and got...")
  10.             thinking()
  11.             if amount > 1:
  12.                 for amount in range(amount - 1):
  13.                     print(f"...a {random.randint(sides) + 1}...")
  14.                     thinking()
  15.                 print(f"...and a {random.randint(sides) + 1}.")
  16.             else:
  17.                 print(f"...a {random.randint(sides) + 1}.")
  18.         elif sides == "inf" or sides == "infinity" or sides == "∞" or sides == "inifnite":
  19.             thinking(6)
  20.             print("Well done, you have jump-started the destruction of the universe. That's terrific.")
  21.     else:
  22.         user_error()
  23.     prog_end()
  24.  
  25. def thinking(zzz = 3):
  26.     for z in range(zzz):
  27.         print(".", end=" ", flush=True)
  28.         time.sleep(0.175)
  29.     print("")
  30.     print("")
  31.  
  32. def prog_end():
  33.     thinking(6)
  34.     input("Press any key to exit")
  35.     print("Bye, nerd.")
  36.     time.sleep(1)
  37.     sys.exit()
  38.  
  39. def user_error():
  40.     thinking(6)
  41.     print("...you can't use that to roll dice. Are you okay?")
  42.     prog_end()
  43.  
  44.  
  45.  
  46. # Uncomment the next two lines if calling the script externally
  47. # (need to write code to adapt to this automatically)
  48. #input1 = sys.argv[1]
  49. #input2 = sys.argv[2]
  50.  
  51.  
  52. # Uncomment the next two lines to ask for user input in the Python shell (rather than accept external input)
  53. input1 = input("How many dice? (1-10)")
  54. input2 = input("How many sides? (2-100)")
  55.  
  56. try:
  57.     input1 = int(input1)
  58. except:
  59.     user_error()
  60.  
  61. thinking()
  62.  
  63. try:
  64.     if input2 == "inf" or input2 == "infinity" or input2 == "∞" or input2 == "inifnite":
  65.         thinking(6)
  66.         print("Well done, you have jump-started the destruction of the universe. That's terrific.")
  67.         prog_end()
  68.     input2 = int(input2)
  69. except:
  70.     user_error()
  71.  
  72. dice(input1, input2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement