Search code examples
pythonalgebrafractions

Python Algebra Fractions


I hate to admit it but this little line of code is giving me some troubles.

print 15 + (-1*(((yearnum + yearnum / 4 - yearnum / 100 + yearnum / 400) + 11) % 7)) % 7

Why is this not equivalent to?

print 15 + (-1*(((497 * yearnum / 400) + 11) % 7)) % 7

Maybe I have completely forgotten how fractions work?


Solution

  • (yearnum + yearnum / 4 - yearnum / 100 + yearnum / 400) does not equal (497 * yearnum / 400) + 11) % 7) as a result of integer division (Python floors the result of integer division).