human
Replace the maximum element in the array by coefficient of range | Utility function to print the contents of the array.
Function to replace the maximum element from the array with the coefficient of range of the array.
Maximum element from the array.
Minimum element from the array.
Calculate the coefficient of range for the array.
Assuming all the array elements are distinct . Replace the maximum element with the coefficient of range of the array.
Print the updated array.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to replace the maximum element in the array by coefficient of range and the other steps required.
 def printArr ( arr , n ) :
	for i in range ( n ) :
		print ( arr [ i ] , end = " ▁ " )
def replaceMax ( arr , n ) :
	max_element = max ( arr )
	min_element = min ( arr )
	ranges = max_element - min_element
	coeffOfRange = ranges / ( max_element + min_element )
	for i in range ( n ) :
		if ( arr [ i ] == max_element ) :
			arr [ i ] = coeffOfRange
			break
	printArr ( arr , n )
if __name__ == " _ _ main _ _ " :
	arr = [ 15 , 16 , 10 , 9 , 6 , 7 , 17 ]
	n = len ( arr )
	replaceMax ( arr , n )