Question

Assignment: USING PYTHON Expected submission: TWO (2) Python files, main.py and HelperClasses.py Make a file called...

Assignment: USING PYTHON

Expected submission: TWO (2) Python files, main.py and HelperClasses.py Make a file called HelperClasses and create a class inside it called Helpers Inside Helpers, create 8 static methods as follows:

1.) Max, Min, Standard_Deviation, Mean
a.) Each of these should take a list as a parameter and return the calculated

value

2.) Bubble

a.) This should take a list as a parameter and return the sorted list 3.) Median

a.) This should take a list as a parameter, should call Bubble to sort the list, then return the median of the list

4.) Mode
a.) This should take a list as a parameter and return the number that is in the

list the most

5.) File_Checking

a.) This should take a string as a parameter and return if a file with that name exists

Inside main, you will generate a list of 50 random numbers from 1-10. Then you will ask the user which function they want to user, output the return value, and loop until they decide to quit.

Do not use: Max, Min, Mean, Mode, Sort, stdev functions built into python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Main.py:

from HelperClasses import HelperClasses

from collections import Counter

import random

def askUser():      #ask user for input to perform operation

    print("1. Max\n2. Min\n3. Standard_Deviation\n4. Mean\n5. Bubble\n6. Mode\n7. File Checking")

    inp = input("Function to use? Enter corresponding no.[1-7]: ")

    return int(inp)

def switch(arg, list): #to call appropriate function

    switcher = {

        1: HelperClasses.max(list),

        2: HelperClasses.min(list),

        3: HelperClasses.Standard_Deviation(list),

        4: HelperClasses.Mean(list),

        5: HelperClasses.Bubble(list),

        6: HelperClasses.Mode(list),

    }

    if arg == 7:

        str = input("File name? :")

        return HelperClasses.File_Checking(str)

    else:

        return switcher.get(arg, "Invalid Code!")

def ask(list): #ask repeatatively

    r = input("Do you want to perform another operation? [Enter Y for yes anything other for no]: ")

    if r.upper() == "Y":

        print(switch(askUser(), list))

        ask(list)

    else:

        print("Quitting...!")

def main(): #main block

    list = [random.randint(1,10) for i in range(50)]    #random generate 50 nums 1-10

    print(list) #print the list

    print(switch(askUser(), list)) #frst operation

    ask(list)   #ask repeatatively

if __name__ == "__main__":

    main()

HelperClasses.py:

from collections import Counter

class HelperClasses:

    @staticmethod

    def max(list):

        maxima = -99999999

        for i in list:

            if maxima < i:

                maxima = i

        return maxima

    @staticmethod

    def min(list):

        minima = 99999999

        for i in list:

            if minima > i:

                minima = i

        return minima

    @staticmethod

    def Mean(list):

        sum, count = 0, 0

        for i in list:

            sum+=i

            count=count+1

        return float(sum/count)

    @staticmethod

    def Standard_Deviation(list):

        m = HelperClasses.Mean(list)

        sum, count = 0, 0

        for i in list:

            sum +=(m-i)*(m-i)

            count=count+1

        return pow(float(sum/count), 0.5)

    @staticmethod

    def Bubble(list):

        arr = list

        n = len(list)

   

        for i in range(n):

            for j in range(0, n-i-1):

                if arr[j] > arr[j+1] :

                    arr[j], arr[j+1] = arr[j+1], arr[j]

        return arr

    @staticmethod

    def Mode(list):

        n = len(list)  

        data = Counter(list)

        get_mode = dict(data)

        mode = [k for k, v in get_mode.items() if v == max(data.values())]

       

        if len(mode) == n:

               get_mode = "No mode found"

        else:

               get_mode = "Mode is / are: " + ', '.join(map(str, mode))   

        return get_mode

    @staticmethod

    def File_Checking(str):

        try:

            f = open(str, mode='r')

        except IOError:

                return "Not Exist"

        if f:

            f.close()

            return "Exist"

OUTPUT:

a Console 1/A In [55]: runfile('C:/Users/achar/main.py', wdir='C:/Users/achar') [1, 3, 10, 2, 5, 7, 2, 9, 10, 10, 8, 7, 5, 10, 3, 10, 9, 9, 2, 7, 3, 1, 3, 7, 4, 9, 3, 10, 8, 1, 3, 6, 10, 10, 3, 4, 3, 1, 10, 9, 8, 2, 1, 3, 5, 2, 5, 10, 6, 6] 1. Max 2. Min 3. Standard_Deviation 4. Mean 5. Bubble 6. Mode 7. File Checking Function to use? Enter corresponding no. [1-7]: 1 10 Do you want to perform another operation? [Enter Y for yes anything other for no]: y 1. Max 2. Min 3. Standard_Deviation 4. Mean 5. Bubble 6. Mode 7. File Checking Function to use? Enter corresponding no. [1-7]: 2 Do you want to perform another operation? [Enter y for yes anything other for no]: y 1. Max 2. Min 3. Standard_Deviation 4. Mean 5. Bubble 6. Mode 7. File Checking Function to use? Enter corresponding no.[1-7]: 3 3.207802986469088 Do you want to perform another operation? [Enter Y for yes anything other for no]: y 1. Max 2. Min 3. Standard_Deviation 4. Mean

We were unable to transcribe this image

O Console 1/A Do you want to perform another operation? [Enter Y for yes anything other for no]: y 1. Max 2. Min 3. Standard_Deviation 4. Mean 5. Bubble 6. Mode 7. File Checking Function to use? Enter corresponding no. [1-7]: 7 File name? :info.txt Exist Do you want to perform another operation? [Enter Y for yes anything other for no]: y 1. Max 2. Min 3. Standard_Deviation 4. Mean 5. Bubble 6. Mode 7. File Checking Function to use? Enter corresponding no. [1-7]: 7 File name? : jbl.txt Not Exist Do you want to perform another operation? [Enter Y for yes anything other for no]: n Quitting...!

Add a comment
Know the answer?
Add Answer to:
Assignment: USING PYTHON Expected submission: TWO (2) Python files, main.py and HelperClasses.py Make a file called...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Expected submission: 1 Python file, Graph_Data.py Make a file called Graph_data Inside this file create 3...

    Expected submission: 1 Python file, Graph_Data.py Make a file called Graph_data Inside this file create 3 functions: 1.) BarGraph: This function should take 5 parameters, X-axis data, y-axis data, X-axis label, y-axis label, title. It will create a bar graph using the above data and display it. 2.) Line Graph: This function is the same as above, except with a line graph instead of a bar graph 3.) SaveGraph: This function is the same as BarGraph, except it saves the...

  • ***NEED SOLUTION IN PYTHON *** 1. Create a main function which only gets executed when the...

    ***NEED SOLUTION IN PYTHON *** 1. Create a main function which only gets executed when the file is directly executed Hint: def main(): pass if __name__ == '__main__': main() 2. Your programs will use a file called scores.txt to store a bunch of user-provided numbers. These can be int or float but their values must be between 0 and 100. Inside the main function, display the current list of numbers to the user and ask if they want to update...

  • Create a file called Sort.py (note the capitalization). Within that file, write two different Python functions....

    Create a file called Sort.py (note the capitalization). Within that file, write two different Python functions. Each function will take an array of integers as a parameter and sort those integers in increasing order. One will use insertion sort, and the other will use selection sort (described below). Simple functions will suffice here; do not create any classes. Your insertion sort function should be called insertion_sort(arr). Your selection sort function should be called selection_sort(arr). Selection sort must use a while...

  • C++ 2.3 Activity 3: Bubble Sort For this activity, you are required to provide files called...

    C++ 2.3 Activity 3: Bubble Sort For this activity, you are required to provide files called act3.cpp as well as a makefile to compile and run it. In your file, act3.cpp, should have a skeleton of a main program as per normal which you will then fill it in as per the following. The objective of this activity is to demonstrate the bubble sort algorithm for arrays. You are going to implement this as a function with the following definition:...

  • Python Programming Topics: list, file input/output You will write a program that allows the user to...

    Python Programming Topics: list, file input/output You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing...

  • Python Lesson Assignment Implement the following 4 functions: fancy_min(a, b) Input: two formal parameters: a and...

    Python Lesson Assignment Implement the following 4 functions: fancy_min(a, b) Input: two formal parameters: a and b Output: return the minimum of a and b Notes: a and b can either be a number or None if a is None, return b if b is None, return a if both are None, return None otherwise return the minimum of a and b do not use the built in function min() fancy_max(a, b) Input: two formal parameters: a and b Output:...

  • Topics: list, file input/output (Python) You will write a program that allows the user to read...

    Topics: list, file input/output (Python) You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing student...

  • Assignment #2: List - Array Implementation Review pages 6-7 in "From Java to C++" notes. Due...

    Assignment #2: List - Array Implementation Review pages 6-7 in "From Java to C++" notes. Due Friday, February 9th, 2017 @ 11:59PM EST Directions Create a List object. Using the following definition (List.h file is also in the repository for your convenience) for a list, implement the member functions (methods) for the List class and store the implementation in a file called List.cpp. Use an array to implement the list. Write the client code (the main method and other non-class...

  • Python program - Write a Python program, in a file called sortList.py, which, given a list...

    Python program - Write a Python program, in a file called sortList.py, which, given a list of names, sorts the names into alphabetical order. Use a one dimensional array to hold the list of names. To do the sorting use a simple sorting algorithm that repeatedly takes an element from the unsorted list and puts it in alphabetical order within the same list. Initially the entire list is unsorted. As each element is placed in alphabetical order, the elements in...

  • In python Count the frequency of each word in a text file. Let the user choose...

    In python Count the frequency of each word in a text file. Let the user choose a filename to read. 1. The program will count the frequency with which each word appears in the text. 2. Words which are the spelled the same but differ by case will be combined. 3. Punctuation should be removed 4. If the file does not exist, use a ‘try-execption’ block to handle the error 5. Output will list the words alphabetically, with the word...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT