Check Even/Odd Pair

Take two numbers and determine whether both are even, both are odd, or one is even and one is odd.

IntermediatePhase 1 - Level 2: Nested If & Multiple ConditionsExample 7 of 10
check-even-odd-pair.py
1# Take two numbers
2num1 = int(input("Enter first number: "))
3num2 = int(input("Enter second number: "))
4
5# Check combinations
6if num1 % 2 == 0 and num2 % 2 == 0:
7 print("Both are even")
8elif num1 % 2 != 0 and num2 % 2 != 0:
9 print("Both are odd")
10else:
11 print("One is even, one is odd")

Output

Enter first number: 4
Enter second number: 6
Both are even

Enter first number: 3
Enter second number: 5
Both are odd

Enter first number: 4
Enter second number: 5
One is even, one is odd

What's going on

Check all possible combinations of even/odd.

Key Concepts:

Both even: num1 % 2 == 0 and num2 % 2 == 0
Both odd: num1 % 2 != 0 and num2 % 2 != 0
Otherwise: one even, one odd