Question

QUESTION 3 40 points Sense Write a Python program using recursion that implements the exponential function ered by the follow

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

# global variables p for calculating power

# and f for calculating factorial

power = 1.0

fact = 1.0

# Recursive Function

def e(x, n) :

  global power, fact

  if (n == 0) :       # Termination condition

    return 1

  

  r = e(x, n - 1)     # Recursive call

  power = power * x   # Update the power of x

  

  fact = fact * n     # Factorial

  

  return (r + power / fact)

print("Enter the value for x:")

x = float(input())

n = 100 #initialize the value of n to a high value since we cannot use infinity

print("Function output:",e(x, n))

# global variables p for calculating power # and f for calculating factorial power = 1.0 fact = 1.0 # Recursive Function def

Add a comment
Know the answer?
Add Answer to:
QUESTION 3 40 points Sense Write a Python program using recursion that implements the exponential function...
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 Question 3 (13 points): Purpose: To practice your ability to modify lists and compute...

    In Python Question 3 (13 points): Purpose: To practice your ability to modify lists and compute with lists of lists Degree of Difficulty: Moderate For this question, you are given some population estimates, by age group, from Statistics Canada for some provinces. Starter File a5q3 starter.py is a file that contains a list of lists, to which the variable Pop-data refers, which represents 2020 population numbers. The first item in Pop_data is a list whose first item is the string...

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