This Python program reads a 4×4 matrix and checks whether all non-border elements are equal to the string "Yes".
Border elements include the first and last rows and columns.
If all inner elements are "Yes", it prints "Yes"; otherwise, it prints "No".
def read_matrix(n: int) -> list[list[str]]:
print(f"Enter elements for a {n}×{n} matrix:")
matrix = []
for i in range(n):
row = input(f"Row {i+1}: ").strip().split()
if len(row) != n:
print("Each row must contain exactly n elements.")
exit()
matrix.append(row)
return matrix
def check_inner_yes(matrix: list[list[str]]) -> str:
n = len(matrix)
for i in range(1, n - 1):
for j in range(1, n - 1):
if matrix[i][j] != "Yes":
return "No"
return "Yes"
# Read and check 4×4 matrix
mat = read_matrix(4)
result = check_inner_yes(mat)
print(f"\nCheck result: {result}")
Input:
No No No No
No Yes Yes No
No Yes Yes No
No No No No
Output:
Check result: Yes