Advertisement
mjawili

Untitled

Jun 9th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. import random
  2.  
  3. def user_input():
  4.     while True:
  5.         try:
  6.             num_dice = int(input("Number of dice? "))
  7.             num_rolls = int(input("Number of rolls? "))
  8.            
  9.             assert(num_dice > 0)
  10.             assert(num_rolls > 0)
  11.            
  12.             return num_dice, num_rolls
  13.         except ValueError:
  14.             print("Enter only whole numbers")
  15.             pass
  16.         except AssertionError:
  17.             print ("Cannot be less than one")
  18.                
  19.     user_unput = (num_dice,num_rolls)
  20.     return user_input
  21.  
  22. def rolls(x):
  23.     rolls_generated = []
  24.     list_of_rolls = []
  25.     for i in range(x[1]):
  26.         sum = int()
  27.         for j in range(x[0]):
  28.             throw = random.randint(1,6)
  29.             sum = sum + throw
  30.         rolls_generated.append(sum)
  31.     for i in range(x[0]*6):
  32.         count = rolls_generated.count(i+x[0])
  33.         list_of_rolls.append(count)
  34.     return list_of_rolls
  35.  
  36. def format(x,y):
  37.    
  38.     ratio = 50 / max(y)
  39.     possibilities = (x[0] * 6 - (x[0]-1))
  40.     for i in range(possibilities):
  41.         label = x[0] + i
  42.         num_stars = int(ratio*y[i])
  43.         try:
  44.             assert(num_stars <= 50)
  45.             print(str(label) + " " + str(num_stars * "*") + " " + str(y[i]))
  46.  
  47.         except AssertionError:
  48.             print ("You can't have more than 50 stars")
  49.    
  50. def main():
  51.     while True:
  52.         a = user_input()
  53.         b = rolls(a)
  54.         format(a,b)
  55.         exit = input("Type 'done' to exit: ")
  56.         if exit == "done":
  57.             break
  58.         else:
  59.             print("")
  60. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement