An off-by-one error produces a value one greater or one less than intended, or performs an operation one time too many or too few. Loop bounds and zero-based indexing are common sources. section 6.1.1 section 6.1
Loop and date examples
A loop using while i <= 10 executes six times when i starts at 5. A Date class that accepts month 2 but indexes ('JAN', 'FEB', ...) directly prints MAR instead of FEB. Subtracting one during indexing, or adding a dummy first element, aligns the public month value with the zero-based sequence. section 6.1.1 section 6.1.1
Listing 6.1 (Program 6.1 SurpriseLoop): main.py
if __name__ == '__main__':
count = 0
i = 5
while i <= 10: #1
count += 1
print(f'{count = }, {i = }')
i += 1
Inspect the loop’s initial value, condition, increment, and printed count to verify its exact execution count. section 6.1.1



