Question

Write a Python function binom_product that takes integer arguments a and b and positive integer argument n and returns the pr

0 0
Add a comment Improve this question Transcribed image text
Answer #1

python code:

#returns the binom product
def binom_product(a,b,n):
#product to be return
product=""
result=0

#calculate the (ax)^3
s=pow(a,n)
result=s
if s!=1:
product=str(s)
product+="x^"
product+=str(n)

#if n==2, calculate the (2xy)
if n==2:
s=a*b*n
result=result*s
if s>=0:
product+="+"
product+=str(s)
product+="xy"
  
#calcualte equation from n-1 to 2
i=n-1
while i>1:
#calcualte the x^i*y
s=pow(a,i)*b*n
result=result*s
if s>=0:
product+="+"
if s!=1:
product+=str(s)
product+="x^"
product+=str(i)
product+="y "

#calcualte the x*y^i
s=pow(b,i)*a*n
result=result*s
if s>=0:
product+="+"
if s!=1:
product+=str(s)
product+="x"
product+="y^"
product+=str(i)
  
#decrease the i value
i=i-1

#calcualte the (by)^n
s=pow(b,n)
result=result*s
if s>=0:
product+="+"
if s!=1:
product+=str(s)
product+="y^"
product+=str(n)

product+="="

#return the product expansion
print(product,end="")
#return result
return result


#call the function and print the expansion
print(round(binom_product(2,-1,3)))
  

code:

binomProduct.py - C:/Users/NIROSHINI/Documents/pythonFiles/binom Product.py (3.8.0) File Edit Format Run Options Window Help

File Edit Format Run Options Window Help 111 while i>l: #calcualte the x^ity S=pow (a,i)*b*n result=result*s if s>=0: product

Type help, copyright, credits or license () for more information. >>> ======= RESTART: C:/Users/NIROSHINI/Documents/p

//for any clarification please do comments. if you found this solution useful, please give me thumbs up

Add a comment
Know the answer?
Add Answer to:
Write a Python function binom_product that takes integer arguments a and b and positive integer argument...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns...

    IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns a LIST consisting of all of the digits of n (as integers) in the same order. Name this function intToList(n). For example, intToList(123) should return the list [1,2,3].

  • Write a Python function, called counting, that takes two arguments (a string and an integer), and...

    Write a Python function, called counting, that takes two arguments (a string and an integer), and returns the number of digits in the string argument that are not the same as the integer argument. Include a main function that inputs the two values (string and integer) and outputs the result, with appropriate labelling. You are not permitted to use the Python string methods (such as count(), etc.). Sample input/output: Please enter a string of digits: 34598205 Please enter a 1-digit...

  • (PYTHON please) Write a function that takes, as an argument, a positive integer n, and creates...

    (PYTHON please) Write a function that takes, as an argument, a positive integer n, and creates a file, named fourBits.txt, containing n randomly generated four-bit binary strings, each on its own line. Examples of four-bit binary strings include “1111” and “0011”. Name this function fourBitStrings(n).

  • With using Python . Write a function that: 1. Takes two arguments and returns the product...

    With using Python . Write a function that: 1. Takes two arguments and returns the product of the arguments. The return value should be of type integer. 2. Takes two arguments and returns the quotient of the arguments. The return value should be of type float. 3. Takes one argument and squares the argument. It then uses the two values and returns the product of the two arguments.(Reuse function in 1.) 4. Takes one argument and prints the argument. Use...

  • Write a python program (recursive.py) that contains a main() function. The main() should test the following...

    Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...

  •  Write a Perl script that accepts exactly 2 integer arguments where the first argument must...

     Write a Perl script that accepts exactly 2 integer arguments where the first argument must be less than the second argument. The script will print a comma separated list of integers starting with the first argument up through the second argument.  The last printed value should be the second command line argument not be followed by a comma.  The script should also be able to handle the following errorsituations: o incorrect number of arguments o the first...

  • Using python Write a Python function called sgm that requests a positive integer n and returns...

    Using python Write a Python function called sgm that requests a positive integer n and returns the series geometric mean of the numbers 1,2,3, . . . n. For example sgm(5) = (5 x 4 x 3 x 2 x 1)1/5 = (120) 1/5 = 2.605 . Write the program so that a user is requested for a positive integer and program prints the series geometric mean of the integer. Example execution: Enter number: 5 series geometric mean of 5...

  • USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and...

    USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and returns a single Boolean value representing whether the given argument is prime (True) or not (False). After writing the function, test it by using a loop to print out all the prime numbers from 1-100. To check your results, the prime numbers from 1-100 are: 2, 3, 5, 7, 11. 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,...

  • Design a function named max that accepts two integer values as arguments and returns the value...

    Design a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two. Need Variable lists, Psuedocode, ipo chart, Flow Chart, and a python...

  • Problem 1. Write a Python function times_i_at_odd(L) that takes as arguments a list L and returns...

    Problem 1. Write a Python function times_i_at_odd(L) that takes as arguments a list L and returns a list consisting of the elements of L multiplied by the index number of the element at odd positions. (Use list comprehensions) >>> times_i_at_odd([1,2,3,4,5,6,7,8,9,10]) [2, 12, 30, 56, 90] Problem 2. Write a recursive function sum_cols(grid, n) that takes a list of lists of integers grid and integer n and returns the sum of column n in grid. For example, the call sum_cols([[1,2,3,4], [10,20,30,40],...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT