Python MOOC question. I'm doing: Exercise 1.8 – For & While Loops 3. Write a program using a for loop that calculates exponentials. Your program should ask the user for a base base and an exponent exp, and calculate baseexp. I'm not sure where the for loop comes into play, as described in the assignment. Maybe i'm reading the assignment wrong? This is what I got: b=input('Enter base: ') n=input('Enter exponent: ') bn=b**n print bn What is the loop supposed to do? Are you supposed to be able to run the program over and over again?

Hey! We 've verified this expert answer for you, click below to unlock the details :)

I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!

From a design standpoint you can use loops to do the exponents math. For example if you wanted to get 5^3 int base = 5, exponent = 3; while(exponent > 0) { base *= exponent; //equivalent to base = base*exponent exponent--; } That's c++ but I think you can get the idea from that

For exercise 1.8, they want you to use what's sometimes called an accumulator. An accumulator is usually created prior to a loop for the purpose of accumulating a sum or a product within the loop. For a sum, the accumulator would usually be initialized to 0, and for a product, it would be usually be initialized to 1. In this problem, we are aiming for a product. If we name our accumulator "acc", we can proceed as follows, after getting the base (b) and exponent (e) from the user ... acc = 1 for i in range(e): acc *= b the accumulator (acc) will contain the result after the loop terminates.

Thank you I think I understand better now. What if I may ask is the benefit of using a for loop to calculate the exponent over using the simple code I posted? #user inputs b for base and n for exponent bn=b**n

Looking for something else?

Not the answer you are looking for? Search for more explanations.

## More answers

Looking for something else?

Not the answer you are looking for? Search for more explanations.