Here is the problem
Implement pow(x, n), which calculates x raised to the power n (i.e., xn).
Example 1:
Input: x = 2.00000, n = 10
Output: 1024.00000
The code seems to be working but for input such as x =
0.00001
n =
2147483647
I get time exceedded
n = 2.00000
x = 2147483647
if x < 0:
n = 1 / n
x = x * (-1)
f=n
h=0
for i in range(x-1):
n = n*n
x=x//2
if x%2!=0:
h += 1
if x == 1:
break
if x == 0:
break
for i in range(h):
n = n*f
h=float(h)
print(n)
This is my second attemp but it doesnt seem to be any better