Created
November 9, 2016 13:33
-
-
Save nicholaskajoh/87409bca2e6eff2ad165d9704937183d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# binomial coeficient | |
import math | |
if __name__ == "__main__": | |
print("#### Binomial Coefficent Calculator ####") | |
print("Use: Given (a + b)^n, p = coefficient of a, q = coefficient of b, t = nth term") | |
# get params n, p, q and t | |
n = int(input("n: ")) | |
p = int(input("p: ")) | |
q = int(input("q: ")) | |
t = int(input("t: ")) | |
# solve | |
k = t-1 | |
C = math.factorial(n) / (math.factorial(n-k) * math.factorial(k)) | |
a = p**(n-k) | |
b = q**k | |
print("Coefficient: ", C*a*b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment