Question: Please solve in python Please inlclude all the conditions specified in the problem Complete the code based on the program below Problem 1 Create a
Please solve in python



Please inlclude all the conditions specified in the problem
Complete the code based on the program below


Problem 1 Create a function called histogram that takes as input a dataset data , a lower bound b, an upper bound h, and a number of bins n, and returns a histogram representation of data with n bins between these bounds. More specifically, your function should: 1. Have input arguments histogram(data, n, b, h), expecting data as a list of floats, n as an integer, and b and h as floats. 2. Print the error message b and h are the same value and return an empty list if b and h are the same number (the width of the histogram is 0) 3. If b is larger than h, re-assign b to h and h to b. 4. If n is equal to 0, return an empty list 5. Initialize the histogram hist as a list of n zeros. 6. Calculate the bin width as W = (h-b), so that hist[@] will represent values in the range (b, b + w). hist[1] in the range [b + w, b + 2w), and so on through hist[n-1] . (Remember that [ is inclusive while ) is not!). 7. Ignore any values in data that are less than or equal to b and greater than or equal to h . *Remember if you have changed n and 'b' in step 3, you would need to work with the new value of n and 'b'. 8. Increment hist[i] by 1 for each value in data that belongs to bin i, i.e., in the range [b + i$w, b + (i+1)*w). 9. Return hist. - At the beginning of your function, be sure to check that n is a positive integer; if not, your code should just return an empty list for hist. Please remember to return an empty list. For example, typing in data = [-2, -2.2, 6, 5.6, 8.3, 10.1, 30, 4.4, 1.9, -3.3, 9, 8] hist = histogram(data, 15, -5, 10) print(hist) should return [0, 1, 1, 1, 0, 1, 1, , 0, 1, 1, e, e, 2, 1] Some other test cases are: data = [-4, -3.2, 6, 7.6, 1.8, 2.2, 30, 2.2, 1.9, -8.3, 6, 5] hist = histogram(data, 10, 10, 0) print(hist) should return [0, 2, 2, 0, 0, 1, 1, 1, 0, 0] and, data = [2,2,2) hist = histogram(data, 5, -2, 3) print(hist) returns [, , , , 3] also, data = (-1,-1,-1,10,10] hist = histogram(data, 5, -1, 10) print(hist) returns [@, a, a, 0, 0] Note: Please include all conditions specified in this problem into your code. Problem 2 Create a function called happybirthday that takes as input three dictionaries, name_to_day, name_to_month, a and name_to_year, and combines them into a single dictionary month_to_all that contains the month as the key and the name, (day, year, age) as the value of the month_to_all dictionary. For this problem, you may assume that the current year is 2022 - i.e. age = 2022 - year. Specifically, your function should: 1. Have input arguments happybirthday(name_to_day, name_to_month, name_to_year), expecting name_to_day as a dictionary mapping a name (string) to a day in the month (integer), name_to_month as a dictionary mapping a name (string) to a month (integer)and name_to_year as a dictionary mapping a name to a year(integer). You may assume all inputs to be valid. 2. Create a new dictionary month_to_all where the keys are all the months contained in name_to_month (note: if a month does not appear in 'name_to_month', it should not be included in 'month_to_all'), and contains information in the following structure name, (day, year, age), with (day, year, age) being the tuple of values from name_to_day, and name_to_year corresponding to name . Note: the value we want in this new dictionary is a tuple, where the first element of the tuple is the name from 'name_to_month' and the second element of the tuple is a tuple of day, year, age. 3. Return month_to_all. For example, typing in name_to_day={ 'jack':14, 'helen':2, 'zach':20} name_to_month={'jack':4, 'helen':2, 'zach':10} name_to_year={'jack':2014, 'helen':2002, 'zach': 1969) should return {'4': ('jack', (14, 2014, 8)), '2': ('helen', (2, 2002, 20)), '10': ('zach', (20, 1969, 53))} Note that the integer values for each month are not in ascending order: dictionaries are unordered data structures, and do not have a set 'order' for keys. Your output may be in a different order than the examples provided, and that is ok. also, name_to_day={'Stive': 24, 'Bill':28, 'Elon':28, 'Jeff':12, 'Mark':14} name_to_month={'Stive':2, 'Bill':11, 'Elon':6,'Jeff":1, 'Mark':5} name_to_year={'Stive': 1955, 'Bill':1955, 'Elon': 1971, 'Jeff': 1964, 'Mark': 1984} should output {'2': ('Stive', (24, 1955, 67)), '11': ('Bill', (28, 1955, 67)), '6': (Elon, (28, 1971, 51)), '1': ('Jeff', ( 1 2 3 def histogram(data, n, b, h): # data is a list # n is an integer # b and h are floats m 4 5 6 # Write your code here 7 8 9 10 11 # return the variable storing the histogram # output should be a list pass 12 13 14 def happybirthday (name_to_day, name_to_month, name_to_year): #name_to_day, name_to_month and name_to_year are dictionaries 15 16 # Write your code here 17 18 19 # return the variable storing name_to_all # Output should be a dictionary 20 21 22 pass 1 from homework2 import histogram 2 2 3 4 data = [4, 3, 8,4,-1, 2, -18, -5, e] hist = histogram(data, 10, -5, 10) print(hist) 5 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
