Question: write a Python program that can work with lists and dictionaries. Assume that you want to use dictionary to find different solutions of the
write a Python program that can work with lists and dictionaries. Assume that you want to use dictionary to find different solutions of the equation below: 2x-3y+z=5 Pass a list of the coefficients to a function. For example for the above equation the list of equations would be: Coeff=[2,-3,1] Also, we know that x,y, and z are integer and generally in the range of -9 to 9. The range of each x,y and z is entered by user. Write a function that generates all the possible described situation with the header: def buildPossibleAnswers(Coeff, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax): Call this function to build all possible answer for this equation. The function displays the prompt to tell the user what to enter. If the user does not enter valid input display the appropriate error message as described below and display the prompt again asking for more input from the user. Repeat this until the user enters valid input. When the user enters valid input return possible combinations of the answers in a list. Error situations: If the user presses enter/return without entering anything display the message 'Missing input!" If the inputs are not integers display the value of the input and the message 'is not valid!' If the inputs are not in the desired range, print 'Out of range!" Write a function that begins with the following header: def computeError(a, k): Given the value of a, the list that is the output of the "buildPossibleAnswers" function and "k" is the desired right-hand side of the equation; for the example above, k-5. The output of "computeErrors" should be a dictionary in which the possible answers are the key element and the difference between the output of the equation because of those values and the expected output is the value for that key element. Note: Keep in mind that a key in a dictionary is in "string"; therefore, you have to convert possible answer to string before adding it to your dictionary. For example if we call two functions buildPossibleAnswers and computeError respectively, the answer should like below for the mentioned equation: a-buildPossibleAnswers([2.-3,1],-9, 9, -9, 9, -9, 9) computeError(a, 5) Your possible answers and errors for the equation 2x-3y+z=5 are: (1,-1,-1): 1. 11.-1, -21: 2, 11.-1.-31: 3, 11.-1, -41: 4, 11,-1,-5): 5, [1,-1, 0:0, 11.-1.1:-1, 11.-1.2]:-2, [1.-1, 3: -3. 11.-1.4: -4, 11.-1.5: -5, 11.-1, 6: -6. [1.-2, -1]: -2. 11, -2, -21:-1, [1.-2.-3]: 0, 11.-2, 4]: 1, [1.-2, -5]: 2, 11, -2, 0: -3, 11.-2, 1:4. [1.-2, 2]: -5, 11.-2, 3]: -6. [1.-2, 4]: -7. 11.-2, 5: -8, 11.-2, 6]: -9, 11. -3, -1]: -5, 11.-3, -2]: -4. 11. -3, -31: -3, ...) (... means that the list might be longer and may continue) In the next step, you have to choose the options that makes the error between the value of the inserted numbers and the actual value zero. In the other word, you have to find the answers of this equation. Write a function that begins with the following header: def findSolutions (R): where R is the output of the previous function "computeErrors" In the final step, write a main script and call all these functions in it and print the possible answers like below: Note: Make sure that your program returns back the answers in list. There are total 12 possible answers for this equations in the desired range: X Y Z 1:[1, -2,-3] 2:[1,-1,0] 3:[1, 0, 3] 4:[1, 1,6] 5:12, -2, -5] 6:12,-1,-2] 7:12, 0, 1] 8:[2, 1, 4] 9:[3,-1,-4) 10:[3,0, -1] 11:13, 1,2] 12:[3, 2, 5) Programmed by Stew Dent. Date: Sun Mar 7 20:20:22 2021 End of processing. The main program does the following: . Using string replication display a line of dashes. Calls all the function that you wrote in the previous steps Display a message that indicates number of possible solution in the desired range of user Showing the time and date at the end of the process Note: There is NO function named main in this program!
Step by Step Solution
There are 3 Steps involved in it
Python code Function to take valid integer inputs from the user def getvalidintegerinputprompt while True userinput inputprompt if userinputstrip prin... View full answer
Get step-by-step solutions from verified subject matter experts
