Logic Building
# Take two numbers
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
# Check combinations
if num1 % 2 == 0 and num2 % 2 == 0:
print("Both are even")
elif num1 % 2 != 0 and num2 % 2 != 0:
print("Both are odd")
else:
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
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