write a Python program that can work with lists and dictionaries. Assume that you want to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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! 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!
Expert Answer:
Answer rating: 100% (QA)
Python code Function to take valid integer inputs from the user def getvalidintegerinputprompt while True userinput inputprompt if userinputstrip prin... View the full answer
Related Book For
Auditing and Assurance services an integrated approach
ISBN: 978-0132575959
14th Edition
Authors: Alvin a. arens, Randal j. elder, Mark s. Beasley
Posted Date:
Students also viewed these programming questions
-
Discuss how environment affects behavior
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
Write an article on communication as culture essays on media and society.
-
You are given the following information about two stocks: (a) Calculate the mean and standard deviation for each stock. (b) Compare the mean, standard deviation, and coefficient of variation of each...
-
Find the transfer function of the OTA filter in fig 11.69. Express Wo and Q in terms of the capacitances and transconductances. What kind of filters is it? Virl 2 En 1
-
Lander Corporation used the following data to evaluate their current operating system. The company sales items for $13 each and used a budgeted selling price of $13 per unit. What is the...
-
P(0.18 < z < 2.46) Find the indicated probability using the standard normal distribution. If convenient, use technology to find the probability.
-
Because a levy of property taxes creates a lien on taxable property, there is no need to reduce anticipated revenues for uncollectible amounts or to write-off delinquent taxes. Do you agree or...
-
This week's discussion and readings on the legal, ethical, and privacy aspects associated with cyber intelligence operations highlight some interesting challenges. Cyber intelligence operations must...
-
The irreversible first-order (wrt partial pressure of A) gas-phase reaction A B is carried out isothermally in a "fluidized" catalytic CSTR containing 50 kg of catalyst. Currently, 50% conversion is...
-
Consider a cache memory with 8 cache blocks (0-7). If the memory block requests are in the following order- 3, 5, 2, 8, 0, 6, 3, 9, 16, 20, 17, 25, 18, 30, 24, 2, 63, 5, 82, 17, 24 What is the hit...
-
Tina is trying to estimate the effect of the assets of a company on its profit, based on 1000 public companies in the UK. She constructed an econometric model in a log-log form and obtained the OLS...
-
Venus Inc. ("VI") operates a passenger train service in the country of Galaxy. VI is the sole operator of the train service in Galaxy. However, there is a host of other modes of transportation...
-
Below are departmental income statements for a guitar manufacturer. The company classifies advertising, rent, and utilities as indirect expenses. The manufacturer is considering eliminating its...
-
(a) The spliced connection shown in the figure below, is under the effect of an axial tension load (N* = 20 kN) originating from transient wind load actions only and acting along the grains of the...
-
Dennis buys a house in 1973 and finances it with a mortgage that carries an annual interest rate of 7 per cent. Inflation in 1973 is 3 per cent, inflation in 1974 is 4 per cent, and inflation in 1975...
-
If the yield of chloroform obtainable from acetone and bleaching powder is 75%. What is the weight of acetone required for producing 30 gm of chloroform ? 2CH3COCH3 + 6CaOCl Ca(CH3COO) + 2CHCl3 +...
-
In Problem 8.43, determine the smallest value of for which the rod will not fall out of the pipe. IA -3 in.-
-
List the four parts of the Code of Professional Conduct, and state the purpose of each.
-
List the supporting documents and records the auditor will examine in a typical payroll audit in which the primary objective is to detect fraud.
-
In verifying accounts payable, it is common to restrict the audit sample to a small portion of the population items, whereas in auditing accrued property taxes, it is common to verify all...
-
What methods can a company use to raise capital?
-
Does higher expected inflation increase, decrease, or have no effect on the required rate of return?
-
You have been asked to consult for an entrepreneur who is assembling investors for a new professional sport league. A critical decision for the league will be whether to organize under a...
Study smarter with the SolutionInn App