import itertools


square = [x for x in range(1, 65)]
grains = [2 ** x for x in range(0, 65)]
board = dict(zip(square, grains))


def on_square(num):
    for k, v in board.iteritems():
        if k == num:
            return v


def total_after(num):
    if num == 1:
        return 1
    else:
        for k, v in board.iteritems():
            if k == num:
                total_after = sum(map(board.get, itertools.takewhile(lambda key: key != v, board)))
    return total_after

print (board)
print (total_after(1))
print(on_square(1))



square = [x for x in range(1, 65)]
grains = [2 ** x for x in range(0, 65)]
board = dict(zip(square, grains))


def on_square(num):
    for k, v in board.iteritems():
        if k == num:
            return v


def total_after(num):
    total = 0
    for i in range(1, num+1):
        total += on_square(i)
    return total

Reformat total_after function + Remove itertools
Reformat  total_after function + Remove itertools

- import itertools
  
  
  square = [x for x in range(1, 65)]
  grains = [2 ** x for x in range(0, 65)]
  board = dict(zip(square, grains))
  
  
  def on_square(num):
      for k, v in board.iteritems():
          if k == num:
              return v
  
  
  def total_after(num):
+     total = 0
+     for i in range(1, num+1):
+         total += on_square(i)
-     if num == 1:
-         return 1
-     else:
-         for k, v in board.iteritems():
-             if k == num:
-                 total_after = sum(map(board.get, itertools.takewhile(lambda key: key != v, board)))
-     return total_after
+     return total
  
- print (board)
- print (total_after(1))
- print(on_square(1))
- 
Reformat total_after function + Remove itertools
## Code Before:
import itertools


square = [x for x in range(1, 65)]
grains = [2 ** x for x in range(0, 65)]
board = dict(zip(square, grains))


def on_square(num):
    for k, v in board.iteritems():
        if k == num:
            return v


def total_after(num):
    if num == 1:
        return 1
    else:
        for k, v in board.iteritems():
            if k == num:
                total_after = sum(map(board.get, itertools.takewhile(lambda key: key != v, board)))
    return total_after

print (board)
print (total_after(1))
print(on_square(1))

## Instruction:
Reformat total_after function + Remove itertools
## Code After:


square = [x for x in range(1, 65)]
grains = [2 ** x for x in range(0, 65)]
board = dict(zip(square, grains))


def on_square(num):
    for k, v in board.iteritems():
        if k == num:
            return v


def total_after(num):
    total = 0
    for i in range(1, num+1):
        total += on_square(i)
    return total
