+ 7

Can you please explain the output of this code?

my_variable = pow(2,2,3) print(my_variable) Answer is 1

14th Mar 2020, 7:15 AM
APC (Inactive for a while)
APC (Inactive for a while) - avatar
3 Answers
+ 8
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_func_pow.asp pow(x, y, z) Returns (x**y) % z Hence, pow(2,2,3) is equivalent to (2**2) % 3 4 % 3 1
14th Mar 2020, 7:19 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
If two parameters are passed to the pow() function (for example, x and y), it returns x to the power of y. If a third parameter is present, it raises x to the power of y and then returns the result modulus that 3rd value. As of the case here: 2^2 = 4, 4 % 3 = 1
14th Mar 2020, 7:22 AM
Axelocity
Axelocity - avatar
0
2
21st Mar 2020, 2:11 AM
Ahmed
Ahmed - avatar