Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . Create a module named formulas that contains the functions below: a . def add ( values ) : This function should return the

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.
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.
c. 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.
d. 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.
Please note: The functions in this module should only return numeric values back to the main program. Dont 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 operators name and all the values. Assume all the values that come after the operators 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

Use of assessments to determine trainees learning styles.

Answered: 1 week ago

Question

7. Discuss the advantages of embedded learning.

Answered: 1 week ago