Question

CODE: PYTHON #1:You may feel free to make multiple functions within any one of these programs.Good...

CODE: PYTHON #1:You may feel free to make multiple functions within any one of these programs.Good programming practice is to have the functions conduct proper error checks for valid input(s)or catch any other possible sources of errors.The functions should give meaningful error messages in case of any errors.

a)Write a single function that takes in a list and returns the maximum and minimum values from the list, the difference between them, and the mean.The function should return all those in a dictionary.

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

"""
  Python program
  To get stats from a list into a dictionary
"""

def getListStats(lis):
  dic = {
          'max' : max(lis),
          'min' : min(lis),
          'diff': max(lis) - min(lis),
          'mean': round(sum(lis)/len(lis),3)
        }
  return dic

print(getListStats([-1, -4, 2, 5, -6, 9]))

# Program ends here

Add a comment
Know the answer?
Add Answer to:
CODE: PYTHON #1:You may feel free to make multiple functions within any one of these programs.Good...
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
  • Intro to Programming and Logic: Python 2, Chapter 8 – Strings (so far have learned the...

    Intro to Programming and Logic: Python 2, Chapter 8 – Strings (so far have learned the way of a program, variables, expressions, statements, functions, interface design, conditional, recursion and iteration) Write a program that takes a string as a parameter. It will analyze the string and return True if it is a valid float number. It will return False if it is not a valid float value. Your function should return True in any of these cases: 0.17, .17, 5.27,...

  • Please write a python function for : greedy: This function takes two inputs: one a graph,...

    Please write a python function for : greedy: This function takes two inputs: one a graph, and the other an ordering of the vertices as a list, and returns the proper vertex-coloring produced by the greedy algorithm over the ordering in the list. Examples: greedy({"A" : ["B", "C"], "B" : ["A"], "C" : ["A"]},[“A”, “B”, “C”]) should return {“A” : 1, “B” : 2, "C" : 2} greedy({“A” : ["B"], "B" : [“A”, “C”],"C" : [“B”, “D”), “D" : ["C"]},[“A”,...

  • Define the functions in Python 3.8 1. Write a function most frequent n that takes a...

    Define the functions in Python 3.8 1. Write a function most frequent n that takes a list of strings and an integer n, and that returns a dictionary where the keys are the top n most frequent unique words in the list, and the values are the frequency of each word: For example, most frequent n(text, 3) should return the dictionary {'is': 2, "the’: 3, 'of': 2}, and most frequent n(text, 2) could return either {'is': 2, 'the’: 3} or...

  • IN PYTHON CODE Question #1 Write a function capital that has one argument: strlist that is...

    IN PYTHON CODE Question #1 Write a function capital that has one argument: strlist that is a list of non-empty strings. If each string in the list starts with a capital letter, then the function should return the value True. If some string in the list does not start with a capital letter, then the function should return the value False You may use any of the string functions that are available in Python in your solution, so you might...

  • VERY URGENT*** THANK YOU IN ADVANCE: THIS IS THE CODE I HAVE GOTTEN SO FAR: PYTHON...

    VERY URGENT*** THANK YOU IN ADVANCE: THIS IS THE CODE I HAVE GOTTEN SO FAR: PYTHON This is a code that is supposed to help someone study/ practice for jeopardy. The two functions described below are required for this assignment. You may add other functions that you think are appropriate: menu() This function, which displays all the user options to the screen, prompt the user for their choice and returns their choice. This function will verify user input and ALWAYS...

  • Python 3 Coding Functions: Here is any code required to help code what is below: def...

    Python 3 Coding Functions: Here is any code required to help code what is below: def pokemon_by_types(db, types): new_db = {} for pokemon_type in types: for key in db: # iterate through all the type in types list if db[key][1] == pokemon_type or db[key][2] == pokemon_type: if key not in new_db: new_db[key] = db[key] return new_db I need help coding the functions listed below in the image: Thank you get types(db): Given a database db, this function determines all the...

  • ON PYTHON: ''' Design the functions described below. RECALL: With functions that do not return a...

    ON PYTHON: ''' Design the functions described below. RECALL: With functions that do not return a value and print a result to the console, to test you must call the function, run it and visually inspect the result for correctness. With functions that return a value, use the print_test function to provide feedback of the test results at the command line. The print_test function is implemented for you at the bottom of this file. RECALL: floating point arithmetic can lose...

  • Comma Code (Using Python Language) Say you have a list value like this: spam = [...

    Comma Code (Using Python Language) Say you have a list value like this: spam = [ 'apples' , 'bananas' , 'tofu', 'cats' ] Write a function that takes a list value as an argument and returns a string will all the items separated by comma and space, with and inserted before the last item. For example, passing the previous spam list to the function would return 'apples, bananas, tofu and cats'. but your function should be able to work with...

  • Using Python write a code for Function 1: A bank charges $10 per month plus the...

    Using Python write a code for Function 1: A bank charges $10 per month plus the following check fees for a commercial checking account: a. $0.10 each for 1-19 checks b. $0.08 each for 20-39 checks c. $0.06 each for 40-59 checks d. $0.04 each for 60 or more checks. (Note that the same fee is charged for all checks. If the customer writes 21 checks, all 21 checks are billed at the $0.08 rate.) The bank also charges an...

  • USING PYTHON 3. For this question, you will build three helper functions and one main function....

    USING PYTHON 3. For this question, you will build three helper functions and one main function. All four functions must work together to draw the letter ‘H. Every line of code written should be inside of a function. Here are the function specifications: 1) Helper function (given): def draw_edges(symbol, width): print(symbol + " "*(width-2) + symbol) 2) Helper function: draw_H(symbol, width, height): This function will draw an "H" symbol, given the symbol, width, and height. This function must call the...

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