Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercise 1 (3 points) Convert the terms of a linear equation into a python dictionary, equation_dict. Store the variables of the equation as keys and
Exercise 1 (3 points) Convert the terms of a linear equation into a python dictionary, equation_dict. Store the variables of the equation as keys and their corresponding coefficients as values in the form of lists. For example, if we have the following equation: x-2y = 20 + 6y, we will have the equation dictionary and the constant as follows: equation_dict-x:111, 'y':-8 constant 20 Return the dictionary as the first parameter of the return statement and the constant of the equation as the second parameter of the return statement. Before forming the dictionaries, make sure that all terms of variables and coefficients are on the left hand side of the equation, and all the constants/intercepts are on the right hand side of the equation i.e. given 6-7y + 4, convert it to 6x - 7y4 In : def getDict (equation): ##INPUT: equation: type: string #OUTPUT: equationdict: type: dictionary equation_dict-) - constant-0 # YOUR CODE HERE return equation_dict, -constant In [ ]: # Testing cell for i in range (0, 5) equation, vc dict, vc_const- generateEquation) print (ve_dict) print(vc const) print ("The equation is: ",equation) equation_dict, constant- getDict (equation) assert len (vc dict)--len (equation dict), "The length of the dictionaries are unequal" assert ve_dict.keys) equation_dict.keys) "The keys of the dictionary do not match for key in vc dict.keys(): assert set(ve dict[key]) set (equation_dict[key]) "The dictionaries do not match" onstants do not match assert vc constconstant, "C print( "Passed
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started