Each edge of the spiral is of square longer than the preceding one. A simple loop draws the edges, increasing the length in each iteration:

MAX_LENGTH = 20
d = 1

while d < MAX_LENGTH:
  walk (d)
  kara.turnRight()
  d = d + 1