papezjustin
papezjustin

Reputation: 2355

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?

Upvotes: 1

Views: 369

Answers (1)

Max
Max

Reputation: 46

(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).

Upvotes: 3

Related Questions