+ 2
Same value within brackets gives a different output compared to within brackets
For the statement print(9 ** 1/2) the output is given as 4.5, but when I print the same statement as print(9 ** (1/2)) I get the output as 3.0, why is that and what is the significance of the brackets in the second statement. Thanks
4 Answers
+ 13
This is because of order or operations (remember PEMDAS?). Items within Parentheses are evaluated first. In the first equation:
9 ** 1 / 2
the Exponent is being evaluated first. 9**1 is still 9, so you do Division next:
9 / 2 = 4.5
For the second equation:
9 ** (1 / 2)
the parentheses are evaluated first. 1 / 2 = 0.5, so you're left with:
9 ** 0.5
An exponent of a half is square rooting, and â9 = 3.
+ 2
The brackets change the order of the arithmetic operations.
Statement 1:
9**1 = 9
9/2 = 4,5
Statement 2: (the operation within the brackets gets executed first)
1/2 = 0,5
9**0,5 = 3
+ 2
Thank You Tamara & Manuel for the quick response!!!
+ 1
Yes he is right it is due to maths rule BODMAS