Question

write a function that returns the value of the binomial expansion for a positive (or zero)...

write a function that returns the value of the binomial expansion for a positive (or zero) integer power n and any valid value of x. first write a function that calculates the value of the rth term. This all has to be done without importing any packages in python. Current code,

def binomial_term_L1(x,n):
return (1+x)**n

but having trouble getting the code for the rth term to work.

Homework Answers

Answer #1
def factorial(n): 
  #function t0 calculate the factorial 
  #of any value n;
    f = 1
    for i in range(2, n+1): # loop to calculate the factorial
        f *= i  
          
    return f 
  
# Function to calculate the rth term of series 
def rthterm(X, r , n): 
      
    # calculating the value of n! 
    nFact = factorial(n) 
  
    # For calculating the value of nCr 
    #1.clculating the value of (!r-1)
    rFact = factorial(r-1) 
    #2.calculating the value of (!n-r+1)
    nrFact = factorial(n-r+1) 
  
    # calculating the value of  
    # X to the power r-1 
    xPow = pow(X, r-1) 
  
    # return  the nCr value
    return(int((nFact * xPow)/(nrFact * rFact)))

X = int(input(" enter the  value of X :  "))
r = int(input(" enter the  value of r :  "))
n = int(input(" enter the  value of n :  "))

#calling the function "rthterm" to calculate nCr
k = (rthterm(X,r,n))
#printing the value of nCr
print("The  Rth term is : " , k) 

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function...
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function `g` representing an increasing function g(x) 2) a number `gmin`, and returns an integer `nmin` such that nmin>0 is the smallest integer that satisfies g(nmin)>gmin. test: def g(n): return 2*n print(lowest_integer(g, 10)) Output: 6
For C++: a) Write a function is_prime that takes a positive integer X and returns 1...
For C++: a) Write a function is_prime that takes a positive integer X and returns 1 if X is a prime number, or 1 if X is not a prime number. b) write a program that takes a positive integer N and prints all prime numbers from 2 to N by calling your function is_prime from part a.
Hello! I am confused on the code for this question. Write a complete Python function called...
Hello! I am confused on the code for this question. Write a complete Python function called Frog, with two integer parameters M and N, where N has the default value of 5. The function computes and returns one of two results: if N is odd it returns the equation 2 * M + N, but if it is even it returns the equation 3 * M - N instead.
Write a function name as 'square' that returns the square of input value. For example, the...
Write a function name as 'square' that returns the square of input value. For example, the main function is given: int main(){     cout << "The square of " << n << " is " << square(n) << endl;     return 0; } In c++ simple code.
// Write a function that returns 0 if x is 0, returns -1 // if x...
// Write a function that returns 0 if x is 0, returns -1 // if x < 0, returns 1 if x > 0 // Your code must follow the Bit-Level Integer Coding Rules // on the textbook (located between hw 2.60 and 2.61). // You can assume w = 32. // The only allowed operations in your code are: // ! ~ & ^ | + << >> // This requirement is more restrictive than the coding rules. //...
Write a function called TaylorSin.m that takes as input an array x, and positive integer N,...
Write a function called TaylorSin.m that takes as input an array x, and positive integer N, and returns the Nth Taylor polynomial approximation of sin(x), centered at a = 0. The first line of your code should read function s = TaylorSin(x,N) HINT: in computing k!, use kfact = k*(k-1)*kfact since you are counting by 2
Python question: Write a function that takes a number and an integer (X,N) in a time...
Python question: Write a function that takes a number and an integer (X,N) in a time complexity of O(log(N)). for an example: calling power(2, 2) would return 4
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
Q2- Write a function solution that, given an integer N, returns the maximum possible value obtained...
Q2- Write a function solution that, given an integer N, returns the maximum possible value obtained by inserting one '5' digit inside the decimal representation of integer N. Examples: 1. Given N = 268, the function should return 5268. 2. Given N = 670, the function should return 6750. 3. Given N = 0, the function should return 50. 4. Given N = −999, the function should return −5999. Assume that: N is an integer within the range [−8,000..8,000].
Write an efficient C++ function that takes any integer value i and returns 2^i ,as a...
Write an efficient C++ function that takes any integer value i and returns 2^i ,as a long value. Your function should not multiply 2 by itself i times; there are much faster ways of computing 2^i.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT