I tried to type out the binomial equation in python but I can\'t figure out how
ID: 3885862 • Letter: I
Question
I tried to type out the binomial equation in python but I can't figure out how to input the values for n, p, etc. How should I approach this problem?
5. [15] Evaluate the binomial distribution Ps(x; n, p) for n 8, p 1/2, and x 0,1,..,8. Do NOT use the built-in binomial function to do these calculations. Submit a copy of your program Make a plot your results (P vs x) Now repeat the calculation for p-1/5, and overlay these results on the same plot. Only integer values of x are defined, so prepare your plot as a histogram using the "step" in PYTHON. How can you distinguish between the two figures on the plot? Don't forget to label the axes In words, how do you interpret these two data sets as they appear on the plot?Explanation / Answer
Use the input function to get input from the console. The functions works as:
Let n and p be the variables where you would store the value of the n and p.
n=int(input("Enter the value of n: "))
p=int(input("Enter the value of p: "))
c=int(input("Enter the value of c: "))
What this does is take the input from console after displaying the message inside the arguments of input and typecasts it to int. By default the input is string type.
Since values of n p and c(a range) are given to you what you can do is simply initialize them as they are given and then use a list to store the result and iterate through a for loop to calculate all the values of the probability.