Computer Science, asked by anindyaadhikari13, 4 months ago

How to display the given series in Python?

1 1 2 2 2 4 3 3 6 4 4 8....N terms.

Logic:

First two terms - 1 and 1, sum = 1 + 1 = 2. Third term = 2.

Next two terms - 2 and 2, sum = 2 + 2 = 4, sixth term = 4 etc.


Note: Don't use more than 1 print statement inside loop. ​

Answers

Answered by s14648anisha00929
1

Answer:

Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!

You have been given a series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!, find out the sum of the series till nth term.

Examples :

Input :n = 5

Output : 2.70833

Input :n = 7

Output : 2.71806

Recommended

Answered by HarishAS
2

Program :

\tt {n = int(in put('Enter\ the\ number\ of\ terms:\ ' ))} \\ \\ \tt{l = [\ ]}\\ \\ \tt{for\ i\ in\ range\ (1,n):} \\\\  {\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\ \tt{a = [i,i] + [i+i]} \\ \\ {\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ } \tt{l.append(a)} \\ \\ \tt{t=[x\ for\ y\ in\ l\ for\ x\ in\ y]}\\ \\ \tt{print(^*t[:n],sep='\ ')}

Explanation :

I am getting lists of sets like [1,1,2] , [2,2,4] , [3,3,6] ... etc using the loop as a and appending all such sets into a list l.

Now this list l is a nested so using list comprehension i have flattened it and  then printing the n terms required.

Hope this helps : )

Similar questions