I'm doing some basis conditional exercises, and I don't know what the % numbers mean in this code
Question:
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…
Answers:
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
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…
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