0

When I do this calculation 2*(5+5/(3+3))*3 I get 30 in Python (2.7). But what it seems is that 2*(5+5/(3+3))*3is equal to 35. Can someone tell me why python gives me the answer of 30 instead of 35? I've tested with JavaScript, Lua and Mac Calculator and they show me 35.

Why does Python calculate wrong?

http://ideone.com/yiFJxS

LUCAS
  • 83
  • 1
  • 7

2 Answers2

6

This happens because of the piece 5/(3 + 3) which evalautes to 0. You need to use either of them as float.

Anshu Kumar
  • 606
  • 6
  • 18
-2

Always assume it's an issue with something you're doing rather than with an entire coding language!

It works fine for me in Python shell. 35 is the expected answer and 35 is what we get! Most likely something on your end or a mis-type / you've miss-commented something out. This is from copy pasting your code above.

edit: Who is more likely to be wrong, an individual? Or the masses? Occams razor. In this case I assumed he was using 3 and not 2.7 which led to the correct assumption as it does work in 3.

MildCorma
  • 1
  • 3
  • If you always assume there's an issue with yourself, you'll never find bugs in the language. – erip Apr 28 '16 at 11:29