[英]You should add explicit return at end of a function if function have return value except none
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 string № 6 接下来告诉我:要么 function 中的所有 return 语句都应该返回一个表达式,要么都不应该
I was trying to output the result to a single variable.我试图将结果 output 转换为单个变量。 I'm just not very good at functions and returning values.
我只是不太擅长函数和返回值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.