PYTHON.
Write the following functions without using any predefined functions unless specified.
def min (dataList) : #returns the smallest value of the data values in dataList
def max (dataList): #returns the largest value
def getRange (dataList)
def mean (dataList) : #returns the average of data values
def median (dataList): #returns the middle value of an ordered list
#note: to sort the list first, may use the predefined sort function
Then write a test1 function to test the above functions using the following data sets.
Write a test2 function that imports the functions in the first task from statistics module and perform the same test as in the second task. Finish with a main function to call test1() and test().
Answer:
# min fucntion to find the minimum value
def min(dataList):
try:
dataList.sort()
return dataList[0]
except:
return "Data list may be empty or contains some non numeric
characters."
# max fucntion to find the maximum value
def max(dataList):
try:
dataList.sort()
return dataList[-1]
except:
return "Data list may be empty or contains some non numeric
characters."
# getrange fucntion is not defined properly so i am just
returning the length of the list
# Kindly add the more informatio about this fucntion
def getRange (dataList):
return len(dataList)
# mean fucntion
def mean (dataList) :
try:
total = 0
for num in dataList:
total += num
mean = total /len(dataList)
return mean
except:
return "Data list may be empty or contains some non numeric
characters."
# median fucntion
def median (dataList):
try:
n = len(dataList)
dataList.sort()
if n % 2 == 0:
median1 = dataList[n//2]
median2 = dataList[n//2 - 1]
median = (median1 + median2)/2
else:
median = dataList[n//2]
return median
except:
return "Data list may be empty or contains some non numeric
characters."
# test1 fucntion
def test1():
d1 = [37,32,46,28,37,41,31]
d2 = [2.5, 5.3, 6.1, 1.34, 3.3, 5, 25, 4.3, 6.0, 0.5]
d3 = []
d4 = "abc"
d5 = [2.5, "abc", 4]
dataset = [d1, d2, d3, d4, d5]
i = 1
for d in dataset:
print("For dataset d" + str(i))
print(min(d))
print(max(d))
print(getRange(d))
print(mean(d))
print(median(d))
i += 1
print()
# test2 fucntion
def test2():
import statistics
d1 = [37,32,46,28,37,41,31]
d2 = [2.5, 5.3, 6.1, 1.34, 3.3, 5, 25, 4.3, 6.0, 0.5]
d3 = []
d4 = "abc"
d5 = [2.5, "abc", 4]
dataset = [d1, d2, d3, d4, d5]
i = 1
for d in dataset:
try:
print("For dataset d" + str(i))
print(min(d))
print(max(d))
print(statistics.mean(d))
print(statistics.median(d))
except:
print("Data list may be empty or contains some non numeric
characters.")
i +=1
print()
# main fucntion
def main():
print("\nTest1:\n")
test1()
print("\nTest2:\n")
test2()
if __name__ == "__main__":
main()
Code Screen shot:
Sample Output:
Note: Let me know if you have any doubt.
PYTHON. Write the following functions without using any predefined functions unless specified. def min (dataList) : ...
Objectives Work with functions Assignment Write each of the following functions using Python. The function header MUST be written as specified. In your main code test all of the specified functions. Each function must have a comment block explaining what it does, what the parameters are and what the return value is. Please remember the following two guidelines: unless the purpose of the function is to generate output DO NOT write to the screen within the function unless the purpose...
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...
Rules: You may NOT use the following built-in functions. sort() sum() max() min() Except for format() all string methods are banned. Except for append() and extend() all list methods are banned. You may not import any module. Make sure to test your code with a variety of inputs. Do not assume the examples in these directions are reflective of the hidden test cases. Part 3 Echo (5 Points) Write a function called echo that takes as argument a list and...
Objective To program using the functional programming paradigm Assignment: Write the following functions using Scheme (or LISP if you prefer) . A function (binomial N k) that returns the binomial coefficients C(N, k), defined recursively as: C(NO) = 1, C(N, N) = 1, and, for 0<k < N E(N, k) = C(N-1, k) + C(N-1, k-1) 2. A function (mod N M) that returns the modulus remainder when dividing N by M 3. A function (binaryToDecimal b) that takes a...
I have to follow functions to perform: Function 1: def calculate_similarity(data_segment, pattern): The aim of this function is to calculate the similarity measure between one data segment and the pattern. The first parameter 'data_segment' is a list of (float) values, and the second parameter 'pattern' is also a list of (float) values. The function calculates the similarity measure between the given data segment and pattern and returns the calculated similarity value (float), as described earlier in this assignment outline. The...
Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...
Hi. Could you help me write the below program? Please don't use any header other than iostream, no Chegg class, no argc/argv. Nothing too advanced. Thank you! For this assignment you are implement a program that can be used to compute the variance and standard deviation of a set of values. In addition your solution should use the functions specified below that you must also implement. These functions should be used wherever appropriate in your solution. With the exception of...
Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...
PYTHON PROGRAM by using functions & dictionary or set. - must create a variable to hold a dictionary or sets - must define a function that accepts dictionaries or sets as an argument A dictionary maps a set of objects (keys) to another set of objects (values). A Python dictionary is a mapping of unique keys to values. For e.g.: a dictionary defined as: released = { "iphone" : 2007, "iphone 3G": 2008, "iphone 3GS": 2009, "iphone 4" : 2010,...
IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as well as make sure the Big 3 are defined. IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined...