To find odd and even numbers in Python, we can use the modulo operator (%). If a number is divisible by 2, then it is even, otherwise it is odd. Here is an example code:
main.py124 chars7 lines
In this code, we prompt the user to enter a number and store it in the variable number
. Then, we use an if statement to check if number
is even, i.e. if it is divisible by 2 with no remainder. If it is, we print a message saying that number
is even. Otherwise, we print a message saying that it is odd.
gistlibby LogSnag