Answer to Question #291175 in Python for Vvv

Question #291175

 Write a python program with algorithm and output to find sum of the following series for n terms: 1 – 2/2! + 3/3! - - - - - n/n!


1
Expert's answer
2022-01-27T09:27:24-0500
# Python3 program for the above approach
 
# Function to find the sum of series

def printSeriesSum(N) :


     

    sum = 0;

 

    for i in range(1, N + 1) :

 

        # Generate the ith term and


        # add it to the sum if i is


        # even and subtract if i is


        # odd


        if (i & 1) :


            sum += i / (i + 1);


      

        else :


            sum -= i / (i + 1);


     
 

    # Print the sum


    print(sum);

 
# Driver Code

if __name__ == "__main__" :

 

    N = 10;

 

    printSeriesSum(N);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS