Question

In: Computer Science

Asks a user to enter n values, then calculates and returns the minimum, maximum, total, and...

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)
---------------------------------------

Solutions

Expert Solution

# 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)))


Related Solutions

Write a C program that asks the user to enter double values (the values can be...
Write a C program that asks the user to enter double values (the values can be positive, zero, or negative). After entering the first double value, the program asks "Would you like to enter another value?", and if the user enters Y or y, the program continues to get additional values and stores these values into a double array (for up to 100 values — use a symbolic #define constant to specify the 100 size limit). The program will need...
Write a program that asks the user to enter 3 grades and computes the minimum and...
Write a program that asks the user to enter 3 grades and computes the minimum and the maximum of those 3 grades and prints it. Hint: Use the Math.min() and Math.max() methods. This program will compute the smallest and highest of 3 grades entered by the user. Enter 3 grades separated by a space: 100 85.3 90.5 Smallest: 85.3 Highest: 100.0 Bye
Write a program that asks the user to enter the total precipitation for each of the...
Write a program that asks the user to enter the total precipitation for each of the twelve months of the year into a list. The program should calculate and display the total precipitation for the year, the average monthly precipitation, and the months with the highest and lowest precipitation amounts. FYI: precipitation is measured in inches. Assume that precipitation amounts are floating-point numbers. You will need a list to store the precipitation amounts and another list to store the names...
in C please! Write a code that asks user for input N and calculates the sum...
in C please! Write a code that asks user for input N and calculates the sum of the first N odd integers. There should be a "pure" method that calculates the sum separately that Main method should call when printing the output.
a). Write a program that asks the user to enter an integer N and prints two...
a). Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and N = root ** power. If no such pair of integers exists, it should print a message to that effect. There are two loops, one for power and one for root. Order the loops so that if N = 64, then your program find that N = 8 ** 2 rather than...
Write a java program that asks user to enter a set of positive integer values. When...
Write a java program that asks user to enter a set of positive integer values. When the user stops (think of sentinel value to stop), the program display the maximum value entered by the user. Your program should recognize if no value is entered without using counter.
Code a program which asks user to enter two strings using Scanner class and returns the...
Code a program which asks user to enter two strings using Scanner class and returns the total number of non-space characters in the Strings. For ex: “Hi there” and “hello” should return 12.
Question Write a C program that asks the user to enter two integers x and n....
Question Write a C program that asks the user to enter two integers x and n. Then the program computes xn (=x * x * x …… (n times)) using for loop. and give me an output please use printf and scanf #include int main(void) {     //Declare required variables             //read two integers x , n from the keyboard                 //compute xn using for loop                     printf("< Your name >\n");...
User asks you to develop a program that calculates and then prints interest earned on a...
User asks you to develop a program that calculates and then prints interest earned on a bank balance. Program should print interest earned for the same balance when interest is accumulated annually, semiannually and quarterly. I need the C++ code!
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT