Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Tasks: 1) Finish implementing the subtract() function.using python 2) Implement the following functions, each of which takes 2 parameters: multiply() # returns the product of

Tasks:

1) Finish implementing the subtract() function.using python

2) Implement the following functions, each of which takes 2 parameters:

multiply() # returns the product of the arguments divide() # returns the quotient of the arguments

3) Implement the following functions, each of which takes 1 parameter:

cube() # returns the cube of the argument; e.g. the cube of 2 is 8 because 2 * 2 * 2 = 8 sqrt() # returns the square root of the argument; e.g. sqrt(4) should return 2; sqrt(2.25) should return 1.5 # hint: a square root is really just a number raised to the 0.5 power; you can use the exponentiation operator or the pow() function to do this

I recommend you call your own functions a few times to test them out. Just print() out the result and see if it makes sense.

Remember: Parameters contain values that are passed in by the caller. You will need to make use of the parameters that each function has. Do not change the parameters. Do not change the names of the parameters and do not change the values of the parameters. Just make use of the values given to you.

Here is the starter code for this assignment:

# In this assignment we are going to write some # basic math functions. The exercise may seem # silly, but it is to give you practice. # Below I have defined the add() function. # Both of these statements are correct about # the add() function: # - "The add() function has two parameters." # - "The add() function takes two arguments." def add(x, y): # <--- function header ''' Return the sum of x and y. ''' return (x + y) # <--- function body # The above function definition just makes a function # object. That means we can use the function if we # want, but nothing will happen unless we call it. # Here is an example: z = add(2, 3) # This call to add() should return the value 5 print(z) # Display the value 5 on the screen. # The add() function did not get executed until line 20. # On line 12 we see that the add() function has parameters x and y. # On line 20 we see that add() was called with arguments 2 and 3. # ============================================================= # Here is a stub for the subtract() function: def subtract(x, y): ''' Return the difference of x and y. ''' pass # A stub is an empty function. # Replace the keyword pass with the correct code. # The subtract() function should give back the value of (x-y). # ============================================================= # The functions add() and subtract() above have TWO parameters. # The function negate() below has ONE parameter. def negate(x): ''' Return the negative of x. Also known as the additive inverse of x. ''' return -x def square(x): ''' Return x squared. ''' return x * x # Note: you could also have written # return x ** 2 # but in most programming languages multiplication is much faster than exponentiation. # These two functions --- negate() and square() --- are given as examples. # You do not need to do anything with them. # =============================================================

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

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

JAVA: x + = 5 is the same as x = 5 + x

Answered: 1 week ago