+ 3
What's the output ? >>> 2**2*2*2*1/2
The answer should be 16.0 but its 8.0 why?
9 odpowiedzi
+ 11
That is because of priority in mathematical operations.
First of all it gonna run 2**2 which is 2^2 = 4
So now equation is 4*2*2*1/2
Now it gonna simply multiply everything which is (16*1/2)
And 16*1/2 is equal 8
+ 2
It's because ** has more priority over *
So, it is basically,
>>> (2**2)*2*2*(1/2) = 4*2*2*0.5 = 8.0
+ 2
Thank you guys...
+ 2
In c it will get error 😂
+ 2
There is a priority in python just like BODMAS in maths.
The priority is
1.paranthese
2.exponents
3.multiplication and division
4.addition and subtraction
Thats why exponent has been calculated first and then rest had been multiplied.
+ 1
But by the way it will give you the result = 8.0
+ 1
Exponents(**) is given more predecence than multiplication (*), so it will be like (2**2)*2*2*1/2
Which will be 16*(1 /2) equals 8
0
8.0
0
Lol you 16/2 and answer will be 8