How to code bernoulli distribution from scratch for curious

To solve a problem, the common ready libraries are used but we don’t search the function how to work and how to serve our purpose. More importantly, if we need to modify a function, we don’t know how to do that.

So, the purpose of this article is how to code bernoulli probability distributions and their some properties in a simple way, without using ready libraries like “SciPy” and gain some basic skills from scratch.

The bernoulli distribution is a discrete distribution that is used when a random experiment is performed and only two results are obtained such as good-bad, positive-negative, success-failure. Those statements are used to describe the probabilities of an event. Bernoulli trial is the simple way to represent an experiment like the outcome of a coin heads or tails, the result of an exam pass or failure, etc.

If X is a random variable and p is a probability of an event with this distribution, then:

bernoulli probability mass function

**Python Code:**

```
#bernoulli probability mass function:
def pmf(x,p):
f = p**x*(1-p)**(1-x)
return f
```

Guide to Python Programming Language

Python is an interpreted, high-level, powerful general-purpose programming language. You may ask, Python’s a snake right? and Why is this programming language named after it?

Python Hello World Program - Your first step towards Python world. Learn how to create the Hello World Python program in PyCharm.

Python Programming Tutorials For Beginners

Today you're going to learn how to use Python programming in a way that can ultimately save a lot of space on your drive by removing all the duplicates. We gonna use Python OS remove( ) method to remove the duplicates on our drive. Well, that's simple you just call remove ( ) with a parameter of the name of the file you wanna remove done.