Question: 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
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.
Step by Step Solution
There are 3 Steps involved in it
Heres a Python script that implements the described functionality C... View full answer
Get step-by-step solutions from verified subject matter experts
