Computer Science, asked by shrutiverma383, 11 months ago

Please write a python code to print below series using loops



Please answer it

Attachments:

Answers

Answered by franktheruler
1

Question:

Program to print 1 – x^2/2! + x^4/4! -…. upto nth term

Answer:

import math    

def series( x  , n ):     // Function

   s = 1

   t = 1

   a = 2

 

   for c in range(1,n):  

       fact = 1  

       for d in range( 1, a+1 ):  

           fact = fact * d      // calculating factorial

           

       t = t * (-1)  

       m = t * math.pow(x, a) / fact     // pow is a in-build function //

       s = s + m    

       a = a + 2

  return s

x = 10

n = 11

print('%f'% Series(x, n))

Similar questions