How to make a function that replaces the exponent feature?
<p>Before hand yes this is a homework question. Well there are two I'd like to ask for help with. The first one is a function that needs to take two numbers (base, exp) and then multiply base by itself by the amount of times that exponent represents. eg. base = 2, exp = 3. it would be 2*2*2. So far this is what I have:</p>

<pre><code>def iterPower(base, exp):

if base and exp &lt;= 0:
    return("The answer is 0")
elif base and exp == 0:
    return("1")
else:
    for i in range(exp):
        ans = base * base
        return ans

print("iterPower(0, 0): should be 1 == "  \
     + str(iterPower(0, 0)))

print("iterPower(5, 3): should be 125 == "  \
     + str(iterPower(5,3)))

print("iterPower(-2.0, 3): should be -8.0 == "  \
     + str(iterPower(-2.0, 3)))
</code></pre>

<p>However when I run the above function. The first test gives me none, the second test gives me just 25, and the last test gives me 4.0. I ran the code itself through a code visualizer to see what's happening(or not happening) and I see that the range is not being utilized. I also notice that as I have it (base * base) would not give a correct answer either. I tried googling and going through the already answered questions here and I come up with nothing. </p>

<p>edit: I know there's a built in operator but the point of the assignment is to not use the operator. The paper practically has giant bold letters saying it's use is banned -,-</p>

<p>You probably just want:</p>

<pre><code>ans = 1
for i in range(exp):
    ans *= base
return ans
</code></pre>

<p>As your last condition.<br>
You also don't need the middle condition.</p>

python python-3.x