Answer to Question #166854 in Python for sri

Question #166854

write a UDF to return the descriptive [sum, count, min, mean, max] for a list of n number of input numbers.


1
Expert's answer
2021-02-25T14:30:31-0500
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))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS