Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def column_sums(square):
- """ Takes a magic square as parameter and returns
- a sum of each column in the square as an array. """
- res = []
- i = 0
- n = 0
- sum_sq = 0
- for (i, sq) in enumerate(square):
- j = 0
- sq_len = len(sq)
- while j < sq_len:
- if n >= len(square):
- print(sum_sq)
- res.append(sum_sq)
- sum_sq = 0
- n = 0
- sum_sq += square[j][i]
- j += 1
- n += 1
- return res
- square = [
- [1, 2, 3, 4],
- [5, 6, 7, 8],
- [9, 10, 11, 12],
- [13, 14, 15, 16]
- ]
- print(column_sums(square))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement