# for factorial and combinations import math # for rolling dice import random # for a convenient average function import numpy as np # generate a random integer in [1, 6] die = random.randint(1, 6) print(die) # reroll the die if we want to die = random.randint(1, 6) print(die) # generate a list of rolls rolls = [random.randint(1, 6) for i in range(5)] print(rolls) # re roll them if we want rolls = [random.randint(1, 6) for i in range(5)] print(rolls) print(np.average(rolls)) rolls = [random.randint(1, 6) for i in range(5)] print(np.average(rolls)) rolls = [random.randint(1, 6) for i in range(1000)] print(np.average(rolls)) rolls = [random.randint(1, 6) for i in range(10000)] print(np.average(rolls)) rolls = [random.randint(1, 6) for i in range(100000)] print(np.average(rolls)) # some examples with factorial print(math.factorial(10)) print(math.factorial(5)) # n choose k print(math.comb(10, 6)) # what are the chances of turtle being happy for # *exactly* 6 of the next 10 days? print(math.comb(10, 6) * (0.85 ** 6) * ((1 - 0.85) ** 4))