Compute average of two numbers without overflow | Python 3 code to compute average of two numbers ; Function to compute average of two numbers ; Driver code ; Assigning maximum integer value ; Average of two equal numbers is the same number ; Function to get the average of 2 numbers
import sys NEW_LINE from math import floor NEW_LINE INT_MAX = 2147483647 NEW_LINE def compute_average ( a , b ) : NEW_LINE INDENT return floor ( ( a + b ) / 2 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = INT_MAX NEW_LINE b = - INT_MAX - 1 NEW_LINE print ( " Actual ▁ average ▁ : ▁ " , INT_MAX ) NEW_LINE print ( " Computed ▁ average ▁ : ▁ " , compute_average ( a , b ) ) NEW_LINE DEDENT