Reading Time: 1 minutes
Odd or Even in Python
Python code to determine whether the given integer is odd or even. Even numbers are multiples of 2, whereas odd numbers are not.
## Even numbers are multiples of 2, whereas odd numbers are not. ## THOUGHT PROCESS: Prompt the user for a number -> place the answer in a variable, convert the data type -> operate on number turn by turn using if statement, print even if even, else print odd. # Input from user number = int(input("Enter a number to be tested: ")) # Logic: determining odd/even status using the modulus arithmetic operator if number % 2 == 0: print(number, "is even.") else: print(number, "is odd.")
Try it here.