<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <p>
<img src="http
Step1:  <center><img src="https
Step2:  we want to build an object that denotes a Bernoulli random variable.
it is desired to be able to sample from that variable an arbitrary number of times, not known at design time.
<ASSISTANT_TASK:>
Python Code:
__AUTHORS__ = {'am': ("Andrea Marino", 
                      "andrea.marino@unifi.it",),
               'mn': ("Massimo Nocentini", 
                      "massimo.nocentini@unifi.it", 
                      "https://github.com/massimo-nocentini/",)}
__KEYWORDS__ = ['Python', 'Jupyter', 'language', 'keynote',]
Explanation: <p>
<img src="http://www.cerm.unifi.it/chianti/images/logo%20unifi_positivo.jpg" 
        alt="UniFI logo" style="float: left; width: 20%; height: 20%;">
<div align="right">
<small>
Massimo Nocentini, PhD.
<br><br>
May 28, 2020: init
</small>
</div>
</p>
<br>
<br>
<div align="center">
<b>Abstract</b><br>
A (very concise) introduction to some Python language constructs.
</div>
End of explanation
def increment(a):
    return a + 1
increment(0)
increment(1)
L = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
L
LL = [increment(a) for a in L]
LL
LLL = [increment(a) for a in LL]
LLL
r = range(10)
r
list(r)
map(lambda i: i + 1, L)
(lambda i: i + 1)(0)
(lambda i: i + 1)(1)
list(map(lambda i: i + 1, L))
M = map(lambda i: i + 1, L)
M
next(M)
next(M)
next(M)
next(M)
next(M)
next(M)
next(M)
next(M)
next(M)
next(M)
next(M)
list(range(10))
list(i for i in range(10))
N = (i for i in range(10))
N
list(N)
next(N)
Explanation: <center><img src="https://upload.wikimedia.org/wikipedia/commons/c/c3/Python-logo-notext.svg"></center>
The Python language documentation
Start at https://docs.python.org/3/index.html for everything.
For the tutorial have a look at https://docs.python.org/3/tutorial/index.html, nicely written and complete.
End of explanation
from random import random # import the random generator, to be used to sample from the uniform distribution
random() # a quick check that the random function works
int(True) # this is a very quick check to see if a Boolean can be used as integer
def Bernoulli(p):
    'This is a generator for a Bernoulli random variable of parameter `p` for success.'
    
    while True:              # forever we loop
        r = random()         # get a sample
        yield int(r <= p)    # if that sample denotes a success or a failure we *yield* that outcome
yield # if we evaluate *yield* not in a context, Python raises an error because it is a construct
help(Bernoulli)
B = Bernoulli(p=0.6) # B is our random variable
B
next(B)
next(B)
next(B)
sample = [next(B) for _ in range(1000)]
sample[:20] # just for a quick evaluation, we print the first 20 elements
from collections import Counter
Counter(sample)
B_flip = map(lambda o: 1-o, B)
B_flip
sample = [next(B_flip) for _ in range(1000)]
sample[:20] # just for a quick evaluation, we print the first 20 elements
def Bernoulli(p):
    'This is a generator for a Bernoulli random variable of parameter `p` for success.'
    
    while True:              # forever we loop
        r = random()         # get a sample
        o = int(r <= p)      # if that sample denotes a success or a failure we *yield* that outcome
        print('B ' + str(o))
        yield o
def flip(o):
    print('flip')
    return 1-o
B_flip = map(flip, Bernoulli(p=0.9))
B_flip
sample = [next(B_flip) for _ in range(20)]
Counter(sample)
class A(object):
    
    def __init__(self, j):
        self.j = j
    
    def __add__(self, i):
        return self.j + i
    
    def __radd__(self, i):
        return self.j + i
    
    def __lt__(self, i):
        return self.j < i
def B(b):
    pass
B
B(3) is None
def B(b):
    ...
increment(4)
a = A()
increment(a)
a = A()
increment(a)
A(3) + 1
1 + A(3)
1 + A(3)
A(4) < 2
Explanation: we want to build an object that denotes a Bernoulli random variable.
it is desired to be able to sample from that variable an arbitrary number of times, not known at design time.
End of explanation
<END_TASK>