How to get the answer for exponents questions
<p>I'm new to python. I'm also a beginner on this subject. So any help would be great! </p>

<p>I'm trying to write a code for calculating the answer for questions like 3^2 = 9 , 2^3 = 8, etc. </p>

<p>I know there is a ** for this. But I need to use while loops and for loops for this. </p>

<p>I don't know what I'm doing wrong and what I need for these loops. I also need the loop to tell the user it's the wrong answer if they enter in a number less than zero. I need to know how it would start the loop from the beginning again if they inputted the wrong answer. Any help would be appreciated!</p>

<p>Here is what I have so far: </p>

<pre><code>base1 = int(input("Base:"))
base2 = 1
exponent = int(input("Exponent:"))
ExpNeeded = True
while ExpNeeded: 
    for hat in range(exponent): 
        base2 = base2 * base1
        print("Answer:" , base2)

    ExpNeeded = False


else:
    print("Please enter a number greater than zero")
</code></pre>

<p>i used your code also you  can use <code>while</code> without ExpNeeded and <code>break</code> loop(<code>while</code>) i.e <code>while True:</code></p>

<pre><code>ExpNeeded = True
while ExpNeeded :
    base2 = 1
    base1=int(input("Base:"))
    while base1&lt;=0:
        print "Please enter a number greater than zero"
        base1=int(input("Base:"))
    exponent=int(input("Exponent:"))
    while exponent&lt;=0:
        print "Please enter a number greater than zero"
        exponent=int(input("exponent:"))
    for hat in range(exponent): 
        base2 = base2 * base1
    print 'answer: ' , base2
    print "to repeat press 1 else press 0"
    if int(input(" "))==1:
        pass
    else:
        ExpNeeded =False
</code></pre>

<p>output:</p>

<pre><code>Base:2
Exponent:5
answer:  32
to repeat press 1 else press 0
 1
Base:-2
Please enter a number greater than zero
Base:6
Exponent:2
answer:  36
to repeat press 1 else press 0
 0
</code></pre>

python python-3.x for-loop while-loop exponential