0
Why is code not working as expected?
When I use the following code, I can't seem to ^2 the output of my function. instead its either adding 2 and subtracting 2. Shouldn't print(oper(a, b)^2) give me an output of 324? def multiply(x, y): return x * y a = 9 b = 2 oper = multiply print(oper(a, b)^2) print((multiply(b,a))^2) print((oper(b,a))-2) print((oper(b,a))+2)
3 ответов
+ 4
In python ^ is logical XOR operator.
And ** is the algebraic exponent operator or commonly said as "to the power".
By the way you can also use math.pow(oper(a, b), 2); just include math in the beginning to use the math library.
+ 12
Replace ^ with **
For exponents in Python there's no ^ symbol instead we use **
+ 1
Many thanks!