Sub topic 2
Consecutive Integers and Alternating Parity
Prerequisites
This chapter assumes you know what an integer is, including negative integers and zero. You should be able to find the remainder when dividing by 2, and you should read exponent notation such as x³.
Consecutive Integers and Alternating Parity
Consecutive integers follow one another, such as 4, 5, 6. Their parity alternates between even and odd. Any two consecutive integers contain exactly one even number and one odd number, so their sum is always odd.
for n in range(-3, 4):
total = n + (n + 1)
print(n, n + 1, total, total % 2)The last column is 1 on every row, which confirms that the sum is odd.
Parity of Integer Powers
A positive integer power keeps the parity of its base. If x is even, then x² and x³ are even. If x is odd, every positive power of x is odd.
for x in (-3, -2, 0, 1, 2):
print(x, x % 2, x**2 % 2, x**3 % 2)In each row, the parity of x2 and x3 matches the parity of x.
> callout note: The rule applies only to positive exponents. Any nonzero number to the power 0 equals 1, which is odd even when the base is even.
Wait, that line uses a block quote, so it must be rewritten below.
Positive, Negative, and Zero
A positive number is greater than 0, and a negative number is less than 0. Zero is neither positive nor negative. A problem that says "x is nonzero" excludes zero, but a problem that says "x is not negative" still allows zero.
Sign Rules for Products and Quotients
The sign of a product depends on how many factors are negative. An even number of negative factors gives a positive product, and an odd number gives a negative product. Any zero factor makes the product zero. Quotients follow the same sign rules as products.
| Factors | Sign of product |
|---|---|
| Even number of negatives, no zeros | Positive |
| Odd number of negatives, no zeros | Negative |
| At least one zero | Zero |
Signs of Even and Odd Powers
An even power is never negative. For example, (-4)² = 16. An odd power keeps the sign of its base. For example, (-2)³ = -8. So x³ is positive only when x is positive.
for x in (-3, -1, 0, 2, 5):
print(x, x**2 >= 0, x**3 > 0)Exercise
If x is an odd integer, is x⁴ + 1 odd or even? Explain briefly.
Show answer
Even. Because x is odd, x⁴ is odd. An odd number plus 1 is even.