Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I'm doing some basis conditional exercises, and I don't know what the % numbers mean in this code

currentYear = int(input('Enter the year: '))
month = int(input('Enter the month: '))
if ((currentYear % 4) == 0 and (currentYear % 100) != 0 or (currentYear % 400) ==0):
       print('Leap Year')

I have no idea what the % numbers in the brackets with the currentYear means. I gather it has something to do with leap years, but how does it become %4, %100 or %400?

I don’t know what this is all about to be honest…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The % symbol in Python is called the Modulo Operator. It returns the remainder of dividing the left hand operand by right hand operand. It’s used to get the remainder of a division problem.

So 100 % 5 == 0

or

100 % 3 == 1 —> Remainder equals 1

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading