+ 2
What rule is using Python in ** 1?
Hey could someone with insight to python explain what rule is applied in using the ** to power a number when 1 is part of it? As soon as 1 is part of the power it cuts off any following power and thus in my term violating the rule of multiplying powers. What's the riddle here? Please see the code example here: https://code.sololearn.com/czHNZG1uNWaW/?ref=app
3 Réponses
+ 5
Exponentiation is right-associative. So the evaluation order goes from right to left, and this is the same as following the usual mathematical notation.
https://stackoverflow.com/questions/47429513/why-is-exponentiation-applied-right-to-left
So x**y**z is evaluated as: x**(y**z)
if you want a different evaluation order, just add parentheses at the right places:
(x**y)**z
+ 3
I'm not sure I understand. But looking at your code, any number to the power of 1 is that number and 1 to any power is 1.
So, 3 to the power of 1 is 3. 1 to the power of 4 is 1. Doesn't matter which order you do those two, the result is the same.
3 to the power of 2 to the power of 1 is the same as 3 to the power of 2.
+ 3
Julian Zimpel , to be precise first every expression is calculated from the inner part. For example 3**1**2**4 => 2**4=> 16=> 1**16=>1=>3**1=>3. Same can be done in any other of your expressions.