Question: This code needs to be in python 3 and the recursion part is the part I'm struggleing with because i can't use a loop and

This code needs to be in python 3 and the recursion part is the part I'm struggleing with because i can't use a loop and needs to return the value

Your assignment is to write a recursive function that computes a given number of terms of the above series to approximate the sine of a given angle. Actually, since you will not be allowed to import modules for this problem, you will need to write two recursive functions, as you will need to call a function to calculate factorials in your Taylor series function.

Reminder: the factorial of an integer is found by multiplying that number by each integer between it and zero.

For example: 6! = 6*5*4*3*2*1 = 720

You will need to write a main function to prompt for input and print the final value.

An example run of the program is given below:

Enter the angle to approximate (in radians): .54

Enter the number of terms to compute: 20

sin(0.54) is approximately 0.514135991653113 >>>

Constraints: ? The angle given will be a float that represents the angle in radians

? You may assume that the given number of terms is a non-negative int

? Your Taylor function and factorial function must be recursive (loops are not allowed)

? Your recursive functions must be pure; i.e., they may not use print statements or get input from the user

? You may not import any modules

this is my code right now:

def main():

def fac(k): #fuction for factorial if k<1: return 1 else: return k*fac(k-1) #this is the part i'm having trouble with def cat(x,input_angle): if x<0: sion=((-1)**x)*(input_angle**(1+2*x))/fac(1+2*x) return sion else: return cat(x,input_angle)+cat(x-1,input_angle) input_angle=float(input("Enter the angle to approximate (in radians): ")) x=int(input("Enter the number of terms to compute: ")) cat(x,input_angle) main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!