Question: I am trying to calculate 5^2 in Python and the result is coming out as 7. I am attaching a snippet of my code. Any idea of what's happening?

I've tried:

```
math.pow(a,b)
a**b
eval(str(x))

```

I am receiving the same result of 7 for each of them. I have also imported math.

This is my current code that I am using:

```
question = ["5^2"]
def checkExponent(self, question):
     for i in range(len(question)):
          if question[i] == "^":
               return(math.pow(int(question[i-1]), int(question[i+1])))

def calculate(self):
     temp = 0
     for i in range(len(self.problemArray)):
          if self.checkExponent(self.problemArray[i]) == "":
               temp = self.checkExponent(self.problemArray[i])
          else:
               temp = eval(str(self.problemArray[i]))
          self.answerArray.append(temp)
          temp = 0

```

I was originally using:

```
def calculate(self):
     temp = 0
     for i in range(len(self.problemArray)):
          temp = eval(str(self.problemArray[i]))
          self.answerArray.append(temp)
          temp = 0

```

Answer: 
`^` is the **bitwise XOR** operator.
If you eval() it then `5^2` becomes `0b101 xor 0b010` so `0b111` = 7.

Use `a ** b`, and avoid using eval.
Python is filled with bunch of awesomeness for the programmers to use
In order to calculate 5^2 simply write `5**2`
I am not able to understand why you insist on using such a long code for such a simple operation.
I accept that this is not the perfect answer for your question , though it is more optimised approach which will be beneficial for you