+ 3

Please can someone explain how '512' is the answer of these code; print(2**3**2). I did mine like (2**3) 2×2×2= (8×8)=64

Exponential

31st Aug 2021, 9:44 AM
Uche Elijah
Uche Elijah - avatar
12 odpowiedzi
+ 10
print(2**3**2) means : -->2**3**2 -->2 to the power of (3 to the power of 2)(3*3)(9) -->2 to the power 9 -->512 it like this a = 3**2 b = 2**a means: b = 2**(3**2) a is evaluated first to give us 3 to the power of 2 and returns 9 a =>3**2 = 9 then b is evaluated as 2 to the power of a to give us 2 to the power of 9 which returns as 512 b=> 2**9 = 512 which means 2**3**2 = 512
31st Aug 2021, 9:49 AM
Pariket Thakur
Pariket Thakur - avatar
+ 7
Lack of brackets, so the python Compiler(interpreter) is solving it from right to left it seems. Its evaluating 3 **2 which is 9, then 2**9 which is 512.
31st Aug 2021, 9:50 AM
Gideon Kane Muemuifo
Gideon Kane Muemuifo - avatar
+ 6
Hi funkey! You can just think about what we're doing in usual mathematics. We can write this expression on a piece of paper like this 2 3 2 So, it can be shorten as 2⁹ which is equal to 512.
31st Aug 2021, 11:52 AM
Python Learner
Python Learner - avatar
+ 3
Ira Gideon Kane When operations have the same rank in the order of precedence python evaluates from left to right. But exponentiation comes before multiplication in python.
31st Aug 2021, 9:59 AM
Simon Sauter
Simon Sauter - avatar
+ 3
Let me explain: 2**3**2 = 2**(3**2).............. [3**2 = 3×3 = 9] = 2**9 = 2×2×2×2×2×2×2×2×2 =512
31st Aug 2021, 11:12 AM
Fꫀⲅძ᥆͟ᥙ᥉᯽
Fꫀⲅძ᥆͟ᥙ᥉᯽ - avatar
+ 2
I appreciate the explanation, thank's you all.
31st Aug 2021, 11:55 AM
Uche Elijah
Uche Elijah - avatar
+ 1
Simon Sauter Thanks !
31st Aug 2021, 10:01 AM
Gideon Kane Muemuifo
Gideon Kane Muemuifo - avatar
+ 1
I am wrong still right to left as computer does not represent top down as such.
1st Sep 2021, 3:14 PM
Omar
Omar - avatar
+ 1
Ans : 2**3**2 = 2 **(3*3) = 2**9 = 512 Because ** works as right to left not left to right like other operators
1st Sep 2021, 3:38 PM
Neha Choudhari
Neha Choudhari - avatar
+ 1
Yes
1st Sep 2021, 11:14 PM
Omar
Omar - avatar
0
both are exponents so you would think expinenents are always to the right not to the left so right side first, but the law of precedence is not clear about it as it says left to right if operation has same level of precedence or identical operations.
1st Sep 2021, 11:01 AM
Omar
Omar - avatar
- 1
Usually, evaluation starts from the left side.Strange
1st Sep 2021, 1:22 PM
ETTAHRA LOUKCH
ETTAHRA LOUKCH - avatar