For an assignment, I must create a program with a function that replaces the "power function" assuming that it is broken for whatever reason. The current model I have works pretty decently, but I'm struggling to get it to work when raising to a 1/2, 1/4, etc. (essentially performing a square root function). I know that the issue lies within floats not cooperating with range, but I personally don't know how to avoid this
def power (value, exp):
num = 1.0
if exp>0:
for function in range(exp):
num = num * value
elif exp<0:
for function in range(-exp):
num = num / value
else:
num = 1
return num
number = float(raw_input("Please enter a the base number you wish to raise to a power (no fractions, decimal allowed): "))
exponent = float(raw_input("Please enter the power you wish to raise the base number to (no fractions, decimal allowed): "))
print "Your base number was:", number
print "You rasied this number to the power of:", exponent
print "The ending product of this operation is:", power(number, exponent)