I am writing a function that takes in two parameters: alpha and beta. It then calculates N, which is the square root of (alpha^2 + beta^2). And then it returns a list [x, y] where x = alpha / N and y = beta /N. However, when I write out this code and run it, it calculates 1^2 incorrectly and says that it is 3 and not 1. This is resulting in an incorrect answer. I have added print statements throughout my code to debug it but I can't find what is going wrong. Here is my code and the output.
def createQubit(alpha, beta):
"""
Parameters:
Probability amplitutde = alpha -> float
Probability amplitutde = beta -> float
Return:
A qubit state -> list [x, y], which represents x|0> + y|1>
"""
# YOUR CODE
print(alpha, beta) #test
print(alpha^2, beta^2) #test
sum_of_sq = alpha^2 + beta^2
print(sum_of_sq) #test
N = math.sqrt(sum_of_sq)
if N > 0:
x = alpha / N
y = beta / N
return [x, y]
pass
print(createQubit(1,1))
#OUTPUT:
#1 1 --> alpha, beta
#3 3 --> alpha^2, beta^2
#0 --> sum_of_sq
#None --> result of function when you set alpha = beta = 1
Can someone help me understand why this is happening?