Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON! PYTHON! 1). Multiplication using Addition Write a function: mul(a,b) that will compute and return the product of two positive integers a and b using

PYTHON! PYTHON!

1). Multiplication using Addition

Write a function: mul(a,b) that will compute and return the product of two positive integers a and b using only a for loop and the addition operator ( + ).

Then, write a new function mul2(a,b) that does the same thing, but uses a while loop rather than a for loop.

2). Exponentiation using Multiplication

Write a function expo(x,y) that computes and returns the exponent xy using only a loop and the multiplication operator.

Then, adjust it so that rather than using the multiplication operator, it uses one of the multiplication functions you wrote in part 1.

Hints:

  • xy is equal to (x * x * x * x ... x), y times.

  • When youre computing a sum using a loop, you start at 0, since anything + 0 is itself. When youre computing a product using a loop, you start at ?, since anything * ? is itself (fill in the ?).

  • If you wrote your mul function from part 1 correctly, then the following two lines should have the same effect, so you can use one to replace the other.

    • var = foo * bar

    • var = mul(foo, bar)

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

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

Know the three main dimensions of the service environment.

Answered: 1 week ago

Question

Understand the roles of signs, symbols, and artifacts.

Answered: 1 week ago

Question

Discuss the key ambient conditions and their effects on customers.

Answered: 1 week ago