How can I check if a number is odd?


#1

Question

How can I check if a number is odd?

Answer

A number is odd if it is not evenly divisible by 2, which means we should make use of the modulo % operator. The modulo operator returns the remainder after devision, so if something is evenly divisible by 2, with a remainder of 0, it isn’t odd!
if my_number % 2 == 0: means a number is even.


FAQ: Learn Python - Practice Makes Perfect - purify