Q.4 WAP to Given two integers x and n, compute 𝑥n.
Solution :-
def power(base, exp):
result = 1
for _ in range(abs(exp)): # Loop runs for absolute value of exponent
result *= base
if exp < 0: # If exponent is negative, take reciprocal
return 1 / result
return result
x = int(input("Enter the base (x): "))
n = int(input("Enter the exponent (n): "))
result = power(x, n)
print(f"{x} raised to the power {n} is: {result}")