1. Create a module named formulas that contains the functions below: a. def add(values): This function...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Create a module named formulas that contains the functions below: a. def add(values): This function should return the sum of all the negative numbers in the list values. If none is present in the list, return the sum as 0. c. b. def subtract(values): This function should return the difference of all the positive numbers in the list values. If none is present in the list, return the difference as 0. def multiply(values): This function should return the product of all the non-zero numbers in the list values. If none is present in the list, return the product as 0. def divide(values): This function should return the result of dividing all the numbers in the list values. If the first number is 0 the result should be 0 except in situations where there are other numbers in the list that are 0; in that case, use the sys.exit method to stop the program and display the exit message Cannot divide by 0. All this logic should be placed in the divide function. d. Please note: The functions in this module should only return numeric values back to the main program. Don't return formatted string output. 2. In JaneDoe3, write code that will: a. Check the length of the arguments being sent via the terminal. i. If the length is less than or equal to 1, with the help of sys.exit, exit the program with the message Need to provide operator. ii. If the length is less than or equal to 3, with the help of sys.exit, exit the program with the message Need to provide at least two values. iii. If the length is greater than 3, retrieve the operator's name and all the values. Assume all the values that come after the operator's name will be numbers. When you retrieve them from the terminal, save them into a list as floats. b. Depending on the name of the operator provided, call the functions in formulas.py to perform the operations. Please note: • Write your program as a script (i.e.., include the if_name_ block). Your results should be displayed to 2 decimal places. main • • • Module names are traditionally lower case so use the name provided when giving your module a name. Look over the final statement in the sample output to see how to deal with an invalid operator name. 1. Create a module named formulas that contains the functions below: a. def add(values): This function should return the sum of all the negative numbers in the list values. If none is present in the list, return the sum as 0. c. b. def subtract(values): This function should return the difference of all the positive numbers in the list values. If none is present in the list, return the difference as 0. def multiply(values): This function should return the product of all the non-zero numbers in the list values. If none is present in the list, return the product as 0. def divide(values): This function should return the result of dividing all the numbers in the list values. If the first number is 0 the result should be 0 except in situations where there are other numbers in the list that are 0; in that case, use the sys.exit method to stop the program and display the exit message Cannot divide by 0. All this logic should be placed in the divide function. d. Please note: The functions in this module should only return numeric values back to the main program. Don't return formatted string output. 2. In JaneDoe3, write code that will: a. Check the length of the arguments being sent via the terminal. i. If the length is less than or equal to 1, with the help of sys.exit, exit the program with the message Need to provide operator. ii. If the length is less than or equal to 3, with the help of sys.exit, exit the program with the message Need to provide at least two values. iii. If the length is greater than 3, retrieve the operator's name and all the values. Assume all the values that come after the operator's name will be numbers. When you retrieve them from the terminal, save them into a list as floats. b. Depending on the name of the operator provided, call the functions in formulas.py to perform the operations. Please note: • Write your program as a script (i.e.., include the if_name_ block). Your results should be displayed to 2 decimal places. main • • • Module names are traditionally lower case so use the name provided when giving your module a name. Look over the final statement in the sample output to see how to deal with an invalid operator name.
Expert Answer:
Answer rating: 100% (QA)
Heres a Python script that implements the described functionality C... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Erin Inc.'s gross income from operations was $1,000,000 and its operating expenses were $600,000, All its activities qualify as domestic production activities. It also received a $100,000 dividend...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
All elements of the structure in Figure P3?47 have the same AE except element 1, which has an axial stiffness of 2AE. Find the displacements of the nodes and the stresses in elements 2, 3, and 4 by...
-
Mansfield Congregational Church (MCC) is a small organization in Connecticut with only seventeen employees. Though its funds are dwindling, the MCC wants to hire a full-time maintenance employee to...
-
A biologist has a 40% solution and a 10% solution of the same plant nutrient. How many cubic centimeters of each solution should be mixed to obtain 25 cc of a 28% solution?
-
The Hickory Cabinet and Furniture Company makes chairs. The fixed cost per month of making chairs is $7,500, and the variable cost per chair is $40. Price is related to demand, according to the...
-
Why is the US not considered part of the GDPR?
-
A new president at Big State University has made student satisfaction with the enrollment and registration process one of her highest priorities. Students must see an advisor, sign up for classes,...
-
A strip of paper is laminated to a same size strip of aluminum foil at 78 o F, and the laminated material is stored at this temperature. If the storage temperature later increases to 95 o F, will the...
-
There is an ongoing debate about the roles of quantitative and qualitative inputs in demand estimation and forecasting. Those in the qualitative camp argue that statistical analysis can only go so...
-
A baseball is thrown upward from the top of a building at an angle of 37 degrees above the horizontal and with an initial speed of 12 m/s. If the baseball is in the air for 5.75 seconds, how high is...
-
What factors influence the selection of one approach over another approach?
-
Describe a specific situation for which each of the following experimental designs is appropriate. Defend your reasoning. a. One-group pretest-posttest design b. Pretest-posttest control group design...
-
Why does ISO 21500:2012 appeal to organisations that have limited pro ject management experience?
-
For the class project, apply the MoSCow prioritisation technique to the requirements you have identified at the initiation stage of the project. What does this tell you about the requirements that...
-
(a) Break into small groups and identify at least two real-life examples of projects in which: (i) The scope and technology are well known. (ii) The scope is well known, but the technology is less...
-
Why do you think one will order a customer design chip regardless of it being time consuming and expensive? 2. Draw the CMOS circuit implementing the following circuit: f = x1x2+x1x3 3. Simplify the...
-
Phosgene, COCl2, is a toxic gas used in the manufacture of urethane plastics. The gas dissociates at high temperature. At 400oC, the equilibrium constant Kc is 8.05 104. Find the percentage of...
-
Explain what is meant by the statement, Unless the complete history of any sample is known with certainty, the analyst is well advised not to spend his or her time in analyzing it.
-
Prepare 50 wt% aqueous NaOH solution in advance and allow the Na 2 CO 3 precipitate to settle overnight. (Na 2 CO 3 is insoluble in this solution.) Store the solution in a tightly sealed polyethylene...
-
Defi ne the following terms: (a) Molarity (b) Molality (c) Density (d) Weight percent (e) Volume percent (f) Parts per million (g) Parts per billion (h) Formal concentration
-
Express the vibration of a machine given by \(x(t)=-3.0 \sin 5 t-2.0 \cos 5 t\) in the form \(x(t)=A \cos (5 t+\phi)\).
-
An exponential function is expressed as \(x(t)=A e^{-\alpha t}\) with the values of \(x(t)\) known at \(t=1\) and \(t=2\) as \(x(1)=0.752985\) and \(x(2)=0.226795\), respectively. Determine the...
-
If the motion of a machine is described as \(8 \sin (5 t+1)=A \sin 5 t+B \cos 5 t\), determine the values of \(A\) and \(B\).
Study smarter with the SolutionInn App