Question: Write a program named powers.py that reads user input for two integers a andb, then computes and displays the value of ab . Assume that

Write a program named powers.py that reads user input for two integers a andb, then computes and displays the value of ab. Assume that both a and b are non-negative.Sounds pretty easy, right? The catch here is that you cannot use Pythons ** operator,or any other built-in way of finding powers. Instead, compute the result by repeatedlymultiplying a \times a \times ...\times a for b times. Your code should work for any non-negative valuesof a and b, including zero. Remember that anything to the 0th power is 1.Hint: Create a variable to store the result, and initialize it to 1. Then write a loop thatrepeats b times. Each iteration multiplies the result by a.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!