1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
bearhunter [10]
2 years ago
10

"Write an iterative function iterPower(base, exp) that calculates the exponential baseexp by simply using successive multiplicat

ion. For example, iterPower(base, exp) should compute baseexp by multiplying base times itself exp times"
Computers and Technology
1 answer:
sp2606 [1]2 years ago
5 0

Answer:

I am writing the function using Python. Let me know if you want the program in some other programming language.            

def iterPower(base, exp):    

    baseexp = 1

    while exp > 0:

        baseexp = baseexp*base

        exp= exp - 1

    return baseexp

base = 3

exp = 2

print(iterPower(base, exp))

Explanation:

  • The function name is iterPower which takes two parameters base and exp. base variable here is the number which is being multiplied and this number is multiplied exponential times which is specified in exp variable.
  • baseexp is a variable that stores the result and then returns the result of successive multiplication.
  • while loop body keeps executing until the value of exp is greater than 0. So it will keep doing successive multiplication of the base, exp times until value of exp becomes 0.
  • The baseexp keeps storing the multiplication of the base and exp keeps decrements by 1 at each iteration until it becomes 0 which will break the loop and the result of successive multiplication stored in baseexp will be displayed in the output.
  • Here we gave the value of 3 to base and 2 to exp and then print(iterPower(base, exp)) statement calls the iterPower function which calculates the exponential of these given values.
  • Lets see how each iteration works:
  • 1st iteration

baseexp = 1

exp>0 True because exp=2 which is greater than 0

baseexp = baseexp*base

               = 1*3 = 3

So baseexp = 3

exp = exp - 1

      = 2 - 1 = 1    

exp = 1

  • 2nd iteration

baseexp = 3

exp>0 True because exp=1 which is greater than 0

baseexp = baseexp*base

               = 3*3 = 9

So baseexp = 9

exp = exp - 1

      = 1-1 = 0    

exp = 0

  • Here the loop will break now when it reaches third iteration because value of exp is 0 and the loop condition evaluates to false now.
  • return baseexp statement will return the value stored in baseexp which is 9
  • So the output of the above program is 9.
You might be interested in
A group of 8 bits is called a... <br> A. hunch <br> B. byte <br> C. dozen <br> D. snack
Mama L [17]
I think that it's called a byte.
5 0
3 years ago
Read 2 more answers
You need to perform maintenance on a router and need to temporarily reroute traffic through another office. which would be the b
Whitepunk [10]
<span>In order to perform maintenance on a router and need to temporarily reroute traffic through another office  the best way to perform this action would be to configure a static route on the router.
</span>By doing this, the router will use the manually-<span>configured routing entry to send the packets.</span>
3 0
3 years ago
Why are there so many problems with drivers?
podryga [215]

D. hope this helped!!!!!

5 0
3 years ago
Using a tag, set the color to green for all tags.
nordsb [41]

Answer:

<style>

p {

background-color: rgb(255, 0, 0);

}

h1 {

background-color: rgb(0, 255, 0);

}

ol {

background-color: rgb(97,51,47);

}

</style>

Explanation:

Put this at the top of your code. It should target the paragraph tag, the header h1 tag, and the Ordered List (OL) tag individually and set their background colors respectively.

It's been a while since I've done CSS so you might have to tweak the syntax a bit, but it should look something like that.

5 0
2 years ago
If you’re looking for a quick, high-level overview of common metrics such as audience growth, website traffic, and total posts,
salantis [7]

Google Analytics, this is a common one but there are others that do the same thing.

7 0
3 years ago
Other questions:
  • What is are example of an engineered item?
    12·1 answer
  • Write a program that will askthe user to enter the amount of a purchase. The program should thencompute the state and county sal
    5·1 answer
  • If you use the assign software to a user option, how does the new software install to the user's computer? 70-411
    10·1 answer
  • Which of the following can spreadsheet programs help a person with? (choose all that apply.)
    9·1 answer
  • The output for the following code will be: Pasta (1 mark)
    6·1 answer
  • A-1 grdening supply is preparing a reprt to hand out to the customerez in pointes form only.why should the reprts writers avoid
    9·2 answers
  • Please help ASAP!
    15·1 answer
  • Choose the tag required for each stated goal.
    12·1 answer
  • What is the full form of the OS?​
    15·2 answers
  • Write a Coral program using integers userNum and x as input, and output userNum divided by x four times.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!