Question

In: Computer Science

Implement the following function in the PyDev module functions.py and test it from a PyDev module...

Implement the following function in the PyDev module functions.py and test it from a PyDev module named :

def statistics(n):
    """
    -------------------------------------------------------
    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)
    ------------------------------------------------------
    """

Sample testing:

Enter number of values: 5
First value: 1
Next value: 2
Next value: -3.4
Next value: 4
Next value: 5.3

Minimum: -3.40
Maximum: 5.30
Total: 8.90
Average: 1.78

Solutions

Expert Solution

def statistics(n):              #  function definition starts
    numbers = []                #   created a list to store numbers
    for i in range (n):
        numbers.append(float(input("Enter the number: ")))        # append values to list
    i = 0
    maximum = numbers[0]           #  initialized minimum to 1st value in the list
    minimum = numbers[0]            #  initialized maximum to 1st value in the list
    total = 0                      #  to calculate sum
    for i in range(n):
        if (numbers[i]>maximum):
            maximum = numbers[i]
        if (numbers[i]<minimum):
            minimum = numbers[i]
        total += numbers[i]                                    #   sum calculated
    print("Sum of numbers is {}.".format(total))    
    print("Average of the numbers is {}.".format(total/n))     #  total/n = average
    print("Minimum value is {}".format(minimum))
    print("Maximum value is {}".format(maximum))

number_of_inputs = int(input("Enter the number of values you want to enter: "))  #  taking input
statistics(number_of_inputs)                    #   calling function
        

OUTPUT:


Related Solutions

Implement the following function in the PyDev module functions.py and test it from a PyDev module...
Implement the following function in the PyDev module functions.py and test it from a PyDev module named : def gym_cost(cost, friends): """ ------------------------------------------------------- Calculates total cost of a gym membership. A member gets a discount according to the number of friends they sign up. 0 friends: 0% discount 1 friend: 5% discount 2 friends: 10% discount 3 or more friends: 15% discount Use: final_cost = gym_cost(cost, friends) ------------------------------------------------------- Parameters: cost - a gym membership base cost (float > 0) friends...
Kernal Modul Programing Quenstion : Implement the following 4 conditions in kernel module programming. 1. Implement...
Kernal Modul Programing Quenstion : Implement the following 4 conditions in kernel module programming. 1. Implement a timer module using the timer function provided by the file LINUX/timer.h 2. In module_init, the timer is initialized using setup_timer and called mod_timer to start the timer. 3. Call back function my_timer_callback when timer expires. 4. When you remove a module, delete the timer.
Implement a function to remove a leaf node from a binary search tree. Using the following...
Implement a function to remove a leaf node from a binary search tree. Using the following class and function definition: class BTNode { public: int item; BTNode *left; BTNode *right; BTNode(int i, BTNode *l=nullptr, BTNode *r=nullptr):item(i),left(l),right(r){} }; BTNode *root = nullptr; BTNode * remove_leaf(int item, bool &removed) { // implement } The remove function will return the node with the item if it's present in the tree. If the node is a leaf node and is removed by the function,...
Write the MIPS assembly codes to implement the following function: copy a block of words from...
Write the MIPS assembly codes to implement the following function: copy a block of words from one address to another. Assume that the starting address of the source block be in register $t1 and that the destination address be in $t2. The instruction also requires that the number of words to copy in $t3 (which is >0, that means how many words are needed to copy). Furthermore, assume that the values of these registers as well as register $t4 can...
Using your solution or your instructor's solution from the Module 8 ungraded practice exercise, implement a...
Using your solution or your instructor's solution from the Module 8 ungraded practice exercise, implement a unit test for the Pair class by adding a main method. Create three small constituent classes (I created PeanutButter, Jelly, and Mustard classes) and insert various combinations of them into an array of Pair objects. Thoroughly test the equals(), hashCode(), and toString() methods from the Pair class with your main method. Note: override the toString() method in each of your constituent classes so they...
Design and implement a C++ class called Module that handles information regarding your assignments for a specific module.
Design and implement a C++ class called Module that handles information regarding your assignments for a specific module. Think of all the things you would want to do with such a class and write corresponding member functions for your Module class. Your class declaration should be well-documented so that users will know how to use it.Write a main program that does the following: Declare an array of all your modules. The elements of the array must be of type Module....
Design, implement, and fully test a Python3 function that converts a number to words (words_from_number(number: int))....
Design, implement, and fully test a Python3 function that converts a number to words (words_from_number(number: int)). It should expect to be passed a natural number (such as 12345) and return the corresponding words (i.e., “twelve thousand three hundred forty-five”). Since Python integers can grow arbitrarily large, your code should be flexible, handling at least 20 digits (realistically, it’s just as easy up to 30 digits). Spell everything correctly, and use correct punctuation (hyphens for forty-five and thirty-seven, no commas or...
Design, implement, and fully test a Python3 function that converts a number to words (words_from_number(number: int))....
Design, implement, and fully test a Python3 function that converts a number to words (words_from_number(number: int)). It should expect to be passed a natural number (such as 12345) and return the corresponding words (i.e., “twelve thousand three hundred forty-five”). Since Python integers can grow arbitrarily large, your code should be flexible, handling at least 20 digits (realistically, it’s just as easy up to 30 digits). Spell everything correctly, and use correct punctuation (hyphens for forty-five and thirty-seven, no commas or...
Implement a non-recursive reverse print of linked list using stack and the main function to test:...
Implement a non-recursive reverse print of linked list using stack and the main function to test: You will need to finish the printReversed_nonrecursive method in ch04.LinkedStack2 class, and the ch04.UseStack2 is the main function to test. public class LinkedStack2<T> extends LinkedStack<T> { private void revPrint(LLNode<T> listRef) { if (listRef != null) { revPrint(listRef.getLink()); System.out.println(" " + listRef.getInfo()); } } public void printReversed() { revPrint(top); } /* use stack to implement non-recursive reverse print */ public void printReversed_nonrecursive() { } public...
Make a transfer function (rational function of s) to implement each of the following frequency responses,...
Make a transfer function (rational function of s) to implement each of the following frequency responses, then implement each in MATLAB and turn in the MATLAB bode diagrams (i.e. frequency response plots) alone with your transfer functions a) an absolute magnitude of 10 at low frequencies and an absolute magnitude of 100 at high frequencies b) an absolute magnitude of 100 at low frequencies and an absolute magnitude of 10 at high frequencies
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT