human
Give me a code to find middle point segment from given segment lengths and the other steps required given the following:
Find middle point segment from given segment lengths | Function that returns the segment for the middle point.
the middle point.
stores the segment index.
increment sum by length of the segment.
if the middle is in between two segments.
if sum is greater than middle point.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to find middle point segment from given segment lengths and the other steps required.
 def findSegment ( n , m , segment_length ) :
	meet_point = ( 1.0 * n ) / 2.0
	sum = 0
	segment_number = 0
	for i in range ( 0 , m , 1 ) :
		sum += segment_length [ i ]
		if ( sum == meet_point ) :
			segment_number = - 1
			break
		if ( sum > meet_point ) :
			segment_number = i + 1
			break
	return segment_number
if __name__ == ' _ _ main _ _ ' :
	n = 13
	m = 3
	segment_length = [ 3 , 2 , 8 ]
	ans = findSegment ( n , m , segment_length )
	print ( ans )