+ 3

What's the output ? >>> 2**2*2*2*1/2

The answer should be 16.0 but its 8.0 why?

6th Jun 2019, 7:51 AM
asim shah
asim shah - avatar
9 ответов
+ 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
6th Jun 2019, 8:05 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 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
6th Jun 2019, 8:40 AM
777
777 - avatar
+ 2
Thank you guys...
6th Jun 2019, 8:41 AM
asim shah
asim shah - avatar
+ 2
In c it will get error 😂
6th Jun 2019, 1:50 PM
Anuj Raghu
Anuj Raghu - avatar
+ 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.
12th Jun 2019, 10:43 AM
Shivam Kumar
Shivam Kumar - avatar
+ 1
But by the way it will give you the result = 8.0
6th Jun 2019, 1:51 PM
Anuj Raghu
Anuj Raghu - avatar
+ 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
11th Jun 2019, 8:03 AM
Chris Mutunga
Chris Mutunga - avatar
0
8.0
7th Jun 2019, 7:55 AM
Somil Khandelwal
0
Lol you 16/2 and answer will be 8
9th Jun 2019, 9:25 AM
danil
danil - avatar