In: Computer Science
Write a function called fnReadInParameters() that takes as parameter(s): • a string indicating the name of the parameter le This function should return a dictionary that stores all of the parameter le data of the SIR model in a format that we will describe further below.
ANSWER:
As a further any specific programming language to work on the problem is not given, I am using the most common language to work with dictionaries i.e. Python to work on the problem.
I have provided the properly commented
and indented code so you can easily copy the code as well as check
for correct indentation.
I have provided the output image of the code so you can easily
cross-check for the correct output of the code.
Have a nice and healthy day!!
PYTHON CODE
# defining function fnReadInParameters
# takes input string indicating the name of the parameter
def fnReadInParameters(stringInput,*params):
# converting dict from parameter names from stringInput and params passed
# in params list
# first fetching all names from stringInput using split method of string
# spliting string by ,
paramnames = stringInput.split(",")
# creating dict using dict function of python bu passing key,value pair in it
# to convert two lists to tuple pairs using zip function of python
resultdict = dict(zip(paramnames,params))
# return dict
return resultdict
# calling function fnReadInParameters and displaying result
result = fnReadInParameters("x,y,z",1,2,3)
print("Result:",result)
OUTPUT IMAGE