Write a program that takes a number and prints whether it is even or odd. (Concepts: modulo operator %, conditionals if/else)
Sample Code:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")Hey team, Day 4 introduces decisions with conditionals! Get a number via input(), convert to integer with int() (for whole numbers; floats would mess up even/odd). Store in num.
The magic is the if statement: It checks a condition. Here, num % 2 == 0—% is modulo, giving the remainder after division. Even numbers divide by 2 with 0 remainder (e.g., 4 % 2 = 0), odds have 1 (5 % 2 = 1). == checks equality (not assignment =!). If true, run the indented code: print("Even"). Otherwise, else runs print("Odd"). Indentation matters—Python uses spaces (usually 4) to group code blocks.
Test: Enter 7—prints "Odd". In 10-15 min, add checks for negative numbers (it works!) or zero. Try without else—what happens if even? This is logic building; conditionals are everywhere in programming!
