Python Forum

Full Version: PEMDAS Violation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Sir can u help me with this code
print 500/11*2%8
print 500%11*2/8
Here the output is 2 & 1 respectively

it is violating PEMDAS rule how ?
Are you asserting that it's violating PEMDAS and asking how, or asking if it is? Do you expect the outputs to be different? What exactly do you expect?
Are you concerned that they are not returning fractional values? If so, that's because you're using Python 2.x, where division of integers returns an integer. Try replacing 500 with 500.0. That makes it a float, and the results of the other operators floats as well.