In: Computer Science
Asks a user to enter n values, then calculates and returns
the minimum, maximum, total, and average of those values.
Use: minimum, maximum, total, average = statistics(n)
-------------------------------------------------------
Parameters:
n - number of values to process (int > 0)
Returns:
minimum - smallest of n values (float)
maximum - largest of n values (float)
total - total of n values (float)
average - average of n values (float)
---------------------------------------
# minimum() returns minimum value among 'n' values of array
def minimum(arr,n):
minValue = arr[0]
for i in range(0,n):
if(minValue>arr[i]):
minValue = arr[i]
return minValue
# maximum() returns maximum value among 'n' values of array
def maximum(arr,n):
maxValue = arr[0]
for i in range(0,n):
if(maxValue<arr[i]):
maxValue = arr[i]
return maxValue
# total sum of 'n' values of array
def total(arr,n):
total=0
for i in range(0,n):
total+=arr[i]
return total
# average of 'n' values of array
def statistics(arr,n):
sum=total(arr,n)
return sum/n
# execution of the program starts from here
# n, variable to store a number of values to be stored
n = int(input("Enter the value of n: "))
# array arr declared
arr = []
print("Enter "+str(n)+" values: ")
for i in range(0,n):
x = int(input())
arr.append(x)
# printing the statistics of 'n' values of array , by calling respective functions
print("Statistics: ")
print("Minimum value: "+str(minimum(arr, n)))
print("Maximum value: "+str(maximum(arr, n)))
print("Total: "+str(total(arr, n)))
print("Average: "+str(statistics(arr, n)))