Power Function using Loops
<p>I just started Python 2.7.
I am trying to make a program that executes power function (using loops) without using <strong>import. math</strong>
I think I got it except my program does not execute negative exponents.
The output only comes out as 1.
Here is what I have so far. </p>

<pre><code>decimal=float(input('Enter the base number:'))
integer=int(input('Enter the exponent number:'))

def power_function(decimal, integer):
    num=1
    for function in range(integer):
        if integer&gt;0:
            num=num*decimal
        if integer&lt;0:
            num=1/(num*decimal)
    return num
print power_function(decimal, integer)
</code></pre>

<p>Fixing based on range of negative value.</p>

<pre><code>def power_function(decimal, integer):
    num=1
    if integer&gt;0:
        for function in range(integer):
            num=num*decimal
    if integer&lt;0:
        num=1.0 # force floating point division
        for function in range(-integer):
            num=num/decimal
    return num
</code></pre>

python python-2.7 function loops