Question

Using Python, write a function recur, which on input a positive integer n retuns the value...

Using Python, write a function recur, which on input a positive integer n retuns the value Bn defined as follows. You can assume that the function is only called with positive integer arguments.

B1 = 5, B2​ = 4

B2​ = Bn-1​* Bn-2​ if n is divisible by 3

B3​ = Bn-1​ + Bn-2​ otherwise

*Please go step by step with explanation*

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

File.py

def recur(n):
if n%3==0:
res = n-1 * n-2
print(res)
else:
res = n-1 + n-2
print(res)
return;
  
n=eval(input("Enter value: "))
recur(n)

Output & Indentation:

Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux 1 def recur (n): 3 5else: Enter value: 5 res n-1 n-2 print (r

Rate an upvote.....Thankyou

Hope this helps....

Add a comment
Know the answer?
Add Answer to:
Using Python, write a function recur, which on input a positive integer n retuns the value...
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
  • How to solve it using Python? 5. Write a function called no_squares which takes an input...

    How to solve it using Python? 5. Write a function called no_squares which takes an input parameter N, a positive integer, and returns: 1 if N is not divisible by a square and has an even number of prime factors -1 if N is not divisible by a square and has an odd number of prime factors 0 if N is divisible by a square For example, no-squares (10) returns 1 (since 10 = 2x5), no-squares (30) returns-1 (since 30...

  • Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument,...

    Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument, and provides an output argument called Primes that is a vector containing all prime numbers between 2 and n, inclusive. Verify the correctness of your code with inserting 13 as the input argument, and check that your output is Primes = [2,3,5,7,11,13]. You are NOT allowed to use any directly relevant MATLAB built-in function such as divisors, etc. NOTE: A prime number is a...

  • Write a program in Python that accepts as input an integer N and a real number...

    Write a program in Python that accepts as input an integer N and a real number c, and outputs the coefficient of the Nth degree term of the Taylor series for the function f(x) = ex centered at c. This process should recur until the user enters a quit code. Erroneous input should be excepted as necessary, and should result in a new prompt.

  • Question 6 of 19 Python The factorial of a positive integer n, fact(n), is defined recursively...

    Question 6 of 19 Python The factorial of a positive integer n, fact(n), is defined recursively as follows: fact(n) 51, when n51 fact(n) 5n * fact(n21), otherwise Define a recursive function fact that returns the factorial of a given positive integer.

  • Please help, using Python Write a Python function sum_of_4th_powers, which accepts one argument. You can assume...

    Please help, using Python Write a Python function sum_of_4th_powers, which accepts one argument. You can assume that the function is only called with an integer n as argument, i.e., no need to worry about invalid inputs. If the argument n can be written as a sum n=a4+b4+c4 with all of a,b,c being non-zero, your function should return such a decomposition. Otherwise your function must return False. For example: sum_of_4th_powers(5) must return False, sum_of_4th_powers(18) could return (1,1,2). *Please go step by...

  • Write a Python function binom_product that takes integer arguments a and b and positive integer argument...

    Write a Python function binom_product that takes integer arguments a and b and positive integer argument n and returns the product of the coefficients in the expansion of (ax + by)”. Example: Let a = 2, b = -1, and n = 3. Then (2x – y)3 = 8x3 – 12x²y + 6xy2 – 43 The product of the expansion coefficients is 8 x -12 x 6 x -1 = 576 Notes: There are two visible test cases and three...

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

  • In Python 5. Write a function named listComprehensionDivisors that has 3 integer inputs, N, n1, and...

    In Python 5. Write a function named listComprehensionDivisors that has 3 integer inputs, N, n1, and n2. Using a single list comprehension to make a list of all of the numbers in the range 1..N that are either divisible by n1 or n2, where n1 and n2 can be any positive integers. After creating the list, your code should print out the following 2 lines: “We are printing all numbers from 1 to that are divisible by or ” “These...

  • IN PYTHON Write a function called printDigits() that requests the user to input a four-digit integer...

    IN PYTHON Write a function called printDigits() that requests the user to input a four-digit integer and prints the digits using math function, as shown below. You are not allowed to process the number as a string. You must process the number using standard arithmetic operators (+, *, /, %, etc.) >>> printDigits() Enter n: 1234 1 2 3 4 >>> printDigits() Enter n: 9876 9 8 7 6 >>>

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

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