human
Sum of series 2 / 3 | Function to find sum of series up - to n terms.
initializing counter by 1.
variable to calculate result.
while loop until nth term is not reached.
boolean type variable for checking validation.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to sum of series 2 / 3 and the other steps required.
 def seriesSum ( n ) :
	i = 1 ;
	res = 0.0 ;
	sign = True ;
	while ( n > 0 ) :
		n = n - 1 ;
		if ( sign ) :
			sign = False ;
			res = res + ( i + 1 ) / ( i + 2 ) ;
			i = i + 2 ;
		else :
			sign = True ;
			res = res - ( i + 1 ) / ( i + 2 ) ;
			i = i + 2 ;
	return res ;
n = 5 ;
print ( round ( seriesSum ( n ) , 6 ) ) ;