Question: Python code!! Assume you keep track of the number of hours you study for each course you are enrolled in daily. You maintain the log
Python code!!
Assume you keep track of the number of hours you study for each course you are enrolled in daily. You maintain the log of your hours in a Python dictionary as follows:
{'355':{'Mon':3,'Wed':2,'Sat':2},'360':{'Mon':3,'Tue':2,'Wed':2,'Fri':1 0},'321':{'Tue':2,'Wed':2,'Thu':3},'322':{'Tue':1,'Thu':5,'Sat':2}}
The keys of the dictionary are the course numbers and the values are the dictionaries which include the number of hours you studies on a particular day of the week. Please note that you may not study for some courses on some days OR you may not study for a particular course at all.
Define a function, addDict(d) which adds up the number of hours you studied on each day of the week and returns the summed values as a dictionary. Note that the keys in the resulting dictionary should be the abbreviations for the days of the week and the values should be the total number of hours you have studied on that day. addDict would return the following for the above dictionary:
{'Fri': 10, 'Mon': 6, 'Sat': 4, 'Thu': 8, 'Tue': 5, 'Wed': 6}
(Important note: Your function should not hardcode the course numbers and days of the week. It should simply iterate over the keys that appear in the given dictionary and should work on any dictionary with arbitrary course numbers and days of the week)
(Important note: When we say a function returns a value, it doesnt mean that it prints the value. Please pay attention to the difference.)
Define a function testaddDict() that tests your addDict(d) function, returning True if the code passes your tests, and False if the tests fail. You can start with the following code:
def addDict(d): #write your code here
def testaddDict(): #write your code here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
