import collections
import numpy as np
def is_square_magic(rows_and_cols):
"""is square magic"""
matrix = [[int(num) for num in input().split()] for _ in range(rows_and_cols)]
matrix_length = np.array(matrix).size
uniqueness_check = len(np.unique(matrix))
ascending_sort = np.unique(matrix)
if matrix_length == uniqueness_check and ascending_sort[-1] == pow(rows_and_cols, 2):
horizontal_flip = np.trace(matrix)
vertical_flip = sum(np.fliplr(matrix).diagonal())
sum_of_rows = np.sum(matrix, axis=1)
sum_of_columns = np.sum(matrix, axis=0)
rows_check = collections.Counter(sum_of_rows)
columns_check = collections.Counter(sum_of_columns)
return (horizontal_flip == vertical_flip).any() and (rows_check == columns_check)
if is_square_magic(int(input())):
print("YES")
else:
print("NO")
string № 6 show me next: Either all return statements in a function should return an expression, or none of them should
I was trying to output the result to a single variable. I'm just not very good at functions and returning values.
Pylint is complaining about R1710
. Add a final return
statement at the end of your function to fix it.
return False
You can read more about this rule here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.