from random import randrange
#
# you may use method 'randrange' for this task
# randrange(n) returns a value from {0,1,...,n-1} randomly
#

#
# your solution is here
#
from random import randrange

for experiment in [100,1000,10000,100000]:
    heads = tails = 0
    for i in range(experiment):
        if randrange(2) == 0: heads = heads + 1
        else: tails = tails + 1
    print("experiment:",experiment)
    print("heads =",heads,"  tails = ",tails)
    print("the ratio of #heads/#tails is",(round(heads/tails,4)))
    print() # empty line

#
# you may use method 'randrange' for this task
# randrange(n) returns a value from {0,1,...,n-1} randomly
#

#
# your solution is here
#
from random import randrange

# let's pick a random number between {0,1,...,99}
# it is expected to be less than 60 with probability 0.6
#     and greater than or equal to 60 with probability 0.4

for experiment in [100,1000,10000,100000]:
    heads = tails = 0
    for i in range(experiment):
        if randrange(100) <60: heads = heads + 1 # with probability 0.6
        else: tails = tails + 1 # with probability 0.4
    print("experiment:",experiment)
    print("heads =",heads,"  tails = ",tails)
    print("the ratio of #heads/#tails is",(round(heads/tails,4)))
    print() # empty line

def biased_coin(N,B):
    from random import randrange
    random_number = randrange(N)
    if random_number < B:
        return "Heads"
    else:
        return "Tails"

def biased_coin(N,B):
    from random import randrange
    random_number = randrange(N)
    if random_number < B:
        return "Heads"
    else:
        return "Tails"

from random import randrange
N = 101
B = randrange(100)

total_tosses = 500
the_number_of_heads = 0
for i in range(total_tosses):
    if biased_coin(N,B) == "Heads":
        the_number_of_heads = the_number_of_heads + 1

my_guess =  the_number_of_heads/total_tosses        
real_bias = B/N
error = abs(my_guess-real_bias)/real_bias*100 

print("my guess is",my_guess)
print("real bias is",real_bias)
print("error (%) is",error)

