write a UDF to return the descriptive [sum, count, min, mean, max] for a list of n number of input numbers.
def GetDescriptive(data):
counter = 0
sumValue = None
minValue = None
maxValue = None
for i in data:
counter += 1
sumValue = i if sumValue == None else sumValue + i
minValue = i if minValue == None else i if i < minValue else minValue
maxValue = i if maxValue == None else i if i > maxValue else maxValue
meanValue = None if counter == 0 else sumValue // counter
return [sumValue, counter, minValue, meanValue, maxValue]
print("Please enter int values: ")
sourceData = [int(i) for i in input().split()]
print("[sum, count, min, mean, max] =", GetDescriptive(sourceData))
Comments
Leave a comment