You should add explicit return at end of a function if function have return value except none

Question:

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.

Asked By: HATRED

||

Answers:

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.

Answered By: Blencer
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.