+ 3

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

The answer should be 16.0 but its 8.0 why?

9 Answers

+ 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

Hot today

I have made a calculator in which my % (Percentage) not work correctly for 100%50 or 100%20.

1 Votes

Тренажер кода

0 Votes

Python palindrome challenge.

1 Votes

Java

0 Votes