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]
3 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]3 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
This term is also called live, or hot, which means that a voltage is present and it can cause an electrical current. Any time an
tangare [24]
B. Energised although this is not as common
3 0
3 years ago
Describe two methods by which viruses can spread.
vlada-n [284]

Answer:

the two methods that can spread viruses are touching and breathing

Explanation:

When there are viruses being spread breathing near another person can caused it to spread because viruses can travel through air. if the viruse is in your systems coming out through the mouth is one way it can travel to another person. That's why wearing a mask is helpful

The other was is touching. Viruses can travel through physical contact. Is hands arent being wash regularly after eating brushing teeth etc it leaves germs and bacteria which is some of the ways and sometimes the main reason as to how viruses are made or created. That's why washing hands are important

Hope's this helps

6 0
2 years ago
HELP PLEASEEEE!!!!!!!
Lubov Fominskaja [6]
This is too little points for a question I’m sorry.
8 0
3 years ago
Which of these photoshoots would benefit from using reflectors?
Vlada [557]

Answer:

I dont really know

Explanation:

So first you would use your brain for this.

2) you would ask your sibling or freind

3) then parents

4) then teacher

5) AND IF you really dont know, use brainly and hope u dont have idoits like me answer this question

8 0
3 years ago
From the given programs and application given above, choose one that you prefer to use in making a computer-generated art and wh
nata0808 [166]
More information is needed to answer this question
4 0
2 years ago
Other questions:
  • Jason is creating a webpage on the basic parts of a camera. He has to use a mix of both images and content for the web page to h
    11·1 answer
  • What is something you can do to stay connected to the relationships in your life while we spend this time at home?
    13·1 answer
  • What are some good editing software apps for pc?
    11·1 answer
  • Which term refers to actions that you would typically perform on a computer to revive it if it functions in an unexpected manner
    15·2 answers
  • What is an online reputation?
    12·2 answers
  • A server of service is responsible for sending the contents of cengage.com to your browser when you type cengage.com into the lo
    12·1 answer
  • George is sketching a wireframe representation of the home page of his website. What aspect of the home page would be impossible
    11·1 answer
  • Proxy download for school
    15·2 answers
  • Write a application that can determine if a 5 digit number you input is a palindrome. If the number is a palindrome then print "
    14·1 answer
  • Which IDEs support multiple high-level programming languages? Select all that apply.
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!