I’m writing a perform that takes in two parameters: alpha and beta. It then calculates N, which is the sq. root of (alpha^2 + beta^2). After which it returns a listing [x, y] the place x = alpha / N and y = beta /N. Nonetheless, after I write out this code and run it, it calculates 1^2 incorrectly and says that it’s Three and never 1. That is leading to an incorrect reply. I’ve added print statements all through my code to debug it however I am unable to discover what goes flawed. Right here is my code and the output.
def createQubit(alpha, beta): """ Parameters: Likelihood amplitutde = alpha -> float Likelihood amplitutde = beta -> float Return: A qubit state -> record [x, y], which represents x|0> + y|1> """ # YOUR CODE print(alpha, beta) #check print(alpha^2, beta^2) #check sum_of_sq = alpha^2 + beta^2 print(sum_of_sq) #check N = math.sqrt(sum_of_sq) if N > 0: x = alpha / N y = beta / N return [x, y] go print(createQubit(1,1)) #OUTPUT: #1 1 --> alpha, beta #Three 3 --> alpha^2, beta^2 #0 --> sum_of_sq #None --> results of perform whenever you set alpha = beta = 1
Can somebody assist me perceive why that is taking place?