0

I'm aware that division and multiplication themselves aren't doable in PEP8 so I would like to know how to find out if a number is perfectly divisible by another number. As an example I need to determine if a given year, any year, is a leap year. To do so I need to know if the year is divisible perfectly by 4, and if so if it's divisible perfectly by 100, is it also by 400. Those being the three criteria. However I've no idea how I'd go about setting up a loop to find if it is divisible by 4 with no remainder and moving on to a second loop to find if it's divisible by 100 and so on, or to return that it isn't a leap year.

1 Answers1

1

If you're dealing with integers, you can just apply the remainder operand %

4 % 2 results in  0
17 % 5 results in 2

To be perfectly divisable by a number, the result must be 0.

Luis Alves
  • 194
  • 2
  • 10