Aha! I found the problem. The actual problem was not the units, it was the range() function. I forgot that range() actually didn't include the final number. To solve it, I replaced
range()
range(1, int(2)+1)
with
range(1, int(2)+2)