Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import copy
- d = """1 2 3 4 5 6 7 8
- 8 7 6 5 4 3 2 1
- 2 3 4 5 6 7 8 9
- 9 8 7 6 5 4 3 2
- 1 3 5 7 9 7 5 3
- 3 1 5 3 2 6 5 7
- 1 7 5 9 7 3 1 5
- 2 6 3 5 1 7 3 2"""
- matrix = [[int(x) for x in line.split()]
- for line in d.split("\n")]
- def print_matrinx(matrix):
- for x in range(len(matrix)):
- for y in range(len(matrix[x])):
- print(f"{matrix[x][y]:3}", end=" ")
- print()
- print_matrinx(matrix)
- def square(m):
- for x in range(len(m)):
- for y in range(len(m[x])):
- m[x][y] = m[x][y]**2
- def square_even(m):
- count = 0
- for x in range(len(m)):
- for y in range(len(m[x])):
- count += 1
- if count % 2 == 0:
- m[x][y] = m[x][y]**2
- def square_less_five(m):
- count = 0
- for x in range(len(m)):
- for y in range(len(m[x])):
- if count < 5:
- m[x][y] = m[x][y]**2
- else:
- return
- count += 1
- def square_first_4_line(m):
- for x in range(4):
- for y in range(len(m[x])):
- m[x][y] = m[x][y]**2
- print("Squares")
- mat = copy.deepcopy(matrix)
- square(mat)
- print_matrinx(mat)
- print("Squares even")
- mat = copy.deepcopy(matrix)
- square_even(mat)
- print_matrinx(mat)
- print("Squares less 5")
- mat = copy.deepcopy(matrix)
- square_less_five(mat)
- print_matrinx(mat)
- print("Squares first 4 line")
- mat = copy.deepcopy(matrix)
- square_first_4_line(mat)
- print_matrinx(mat)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement