min max python code example
Example 1: python maths max value capped at x
def clamp(n, minn, maxn):
return max(min(maxn, n), minn)
Example 2: python get min from array
>>> arr = [1, 3.14159, 1e100, -2.71828]
>>> min(arr)
-2.71828
Example 3: min() python
x = min(1, 2)
Example 4: min max code in python
listA = [18, 19, 21, 22]
print('The smallest number from listA is:', min(listA))
print('The largest number from listA is:', max(listA))
strA = 'AppDividend'
print('The smallest character from strA is:', min(strA))
print('The largest character from strA is:', max(strA))
strA = 'AppDividend'
strB = 'Facebook'
strC = 'Amazon'
print('The smallest string is:', min(strA, strB, strC))
print('The largest string is:', max(strA, strB, strC))
Example 5: MIn-Max problem in python
x = sum(arr)
minValue = x - max(arr)
maxValue = x - min(arr)
print(minValue, maxValue)