| 4 | |
| 5 | |
| 6 | class Squares: |
| 7 | def __init__(self, max): |
| 8 | self.max = max |
| 9 | self.sofar = [] |
| 10 | |
| 11 | def __len__(self): |
| 12 | return len(self.sofar) |
| 13 | |
| 14 | def __getitem__(self, i): |
| 15 | if not 0 <= i < self.max: |
| 16 | raise IndexError |
| 17 | n = len(self.sofar) |
| 18 | while n <= i: |
| 19 | self.sofar.append(n * n) |
| 20 | n += 1 |
| 21 | return self.sofar[i] |
| 22 | |
| 23 | |
| 24 | def add(a, b): |