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).

  • 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...

  • Write a Python function cardinality() that takes in three Python set objects, representing sets of between...

    Write a Python function cardinality() that takes in three Python set objects, representing sets of between 0 and 50 integers, AA, BB, and UU. Your function should return a single non-negative integer value for the cardinality of the set below. AA and BB are subsets (not necessarily proper) of the universal set UU. |P(A¯¯¯¯∩B)||P(A¯∩B)| Note 1: You can copy-paste the code declaring the various visible test cases below. We strongly encourage you to do this to test your code. Note...

  • In Python beginner code: Write a function named even_div, that takes two arguments (you can safely...

    In Python beginner code: Write a function named even_div, that takes two arguments (you can safely assume that both arguments will always be non-zero integers). When this function is called, it should return how many times the first argument can be divided by the second argument, if it is evenly divisible (no remainder). If it is not evenly divisible, the function should return 0. Examples: even_div(5, 2) will return 0 (5 divided by 2 is 2.5, not evenly divisible) even_div(10,...

  • 1. Write a Lisp function called piece which takes a single argument x and implements the followin...

    1. Write a Lisp function called piece which takes a single argument x and implements the following piecewise linear function: piece(x) = x if 0 < x < 1 2. Write a Lisp function called intList which takes two integer arguments, a and b and returns the list of all integers from a to b (inclusive at both ends). For example, (intList 3 8) should return (345678) 1. Write a Lisp function called piece which takes a single argument x...

  • 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...

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
ADVERTISEMENT