# Cmput 455 sample code # Guessing the unknown winrate p from a Bernoulli distribution # Written by Martin Mueller from bernoulli import bernoulliExperiment import random p = random.random() input_n = input("I created a random p for Bernoulli experiments. How many experiments should I do? ") try: n = int(input_n) except ValueError: print("Invalid int") wins = 0 for i in range(n): wins += bernoulliExperiment(p) print("{} runs {} wins, empirical winrate {}".format(n, wins, wins / n)) input_guessed_p = input("Guess the value of p: ") try: guessed_p = float(input_guessed_p) except ValueError: print("Invalid float") print("You guessed {}. The true value is {}".format(guessed_p, p))