The binomial coefficient () is an integer equal to nx(n-1) × (n _ 2) × ×(n-k+1)
ID: 3740676 • Letter: T
Question
The binomial coefficient () is an integer equal to nx(n-1) × (n _ 2) × ×(n-k+1) 1 x 2 xx k k)k!(n-k)! when k 2 1, or () 1 when k 0. a) Using this form for the binomial coefficient, write a user-defined function binomial(n,k) that calculates the binomial coefficient for given n and k. Make sure your function returns the answer in the form of an integer (not a float) and gives the correct value of 1 for the case where k 0. b) Using your function write a program to print out the first 20 lines of "Pascal's triangle." The nth line of Pascal's triangle contains n 1 numbers, which are the coefficients () (1), and so on up to (). Thus the first few lines are just need solution for part c 1 21 1331 14641 c) The probability that an unbiased coin, tossed n times, will come up heads k times is (R)/2. Write a program to calculate (a) the total probability that a coin tossed 100 times comes up heads exactly 60 times, and (b) the probability that it comes up heads 60 or more times. need to write in python spyderExplanation / Answer
a)
import math
x = 100
y = 60
if y == x:
print(1)
elif y == 1:
print(x)
elif y > x:
print(0)
else:
a = math.factorial(x)
b = math.factorial(y)
c = math.factorial(x-y)
div = a // (b * c)
res = div / math.pow(2,x)
print(res)
b)
import math
x = 100
y = 60
if y == x:
print(1)
elif y == 1:
print(x)
elif y > x:
print(0)
else:
res = 0
for j in range(60,100):
a = math.factorial(x)
b = math.factorial(j)
c = math.factorial(x-j)
div = a // (b * c)
res = res + div
res = res / math.pow(2,100)
print(res)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.