Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def user_input():
- while True:
- try:
- num_dice = int(input("Number of dice? "))
- num_rolls = int(input("Number of rolls? "))
- assert(num_dice > 0)
- assert(num_rolls > 0)
- return num_dice, num_rolls
- except ValueError:
- print("Enter only whole numbers")
- pass
- except AssertionError:
- print ("Cannot be less than one")
- user_unput = (num_dice,num_rolls)
- return user_input
- def rolls(x):
- rolls_generated = []
- list_of_rolls = []
- for i in range(x[1]):
- sum = int()
- for j in range(x[0]):
- throw = random.randint(1,6)
- sum = sum + throw
- rolls_generated.append(sum)
- for i in range(x[0]*6):
- count = rolls_generated.count(i+x[0])
- list_of_rolls.append(count)
- return list_of_rolls
- def format(x,y):
- ratio = 50 / max(y)
- possibilities = (x[0] * 6 - (x[0]-1))
- for i in range(possibilities):
- label = x[0] + i
- num_stars = int(ratio*y[i])
- try:
- assert(num_stars <= 50)
- print(str(label) + " " + str(num_stars * "*") + " " + str(y[i]))
- except AssertionError:
- print ("You can't have more than 50 stars")
- def main():
- while True:
- a = user_input()
- b = rolls(a)
- format(a,b)
- exit = input("Type 'done' to exit: ")
- if exit == "done":
- break
- else:
- print("")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement