+ 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

19th Apr 2018, 7:16 AM
Raghavendra Sharma
4 Respuestas
+ 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.
19th Apr 2018, 7:26 AM
Tamra
Tamra - avatar
+ 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
19th Apr 2018, 7:29 AM
Manuel Probst
+ 2
Thank You Tamara & Manuel for the quick response!!!
19th Apr 2018, 7:31 AM
Raghavendra Sharma
+ 1
Yes he is right it is due to maths rule BODMAS
1st May 2018, 12:14 PM
SIDDHANT