TheAlgorithms/Python · error · ValueError
Each row in the matrix must have exactly {size} characters.
Error message
Each row in the matrix must have exactly {size} characters. What it means
Error "Each row in the matrix must have exactly {size} characters." thrown in TheAlgorithms/Python.
Source
Thrown at matrix/matrix_based_game.py:87
Traceback (most recent call last):
...
ValueError: The matrix dont match with size.
>>> validate_matrix_content(['aa%', 'aaa', 'aaa'], 3)
Traceback (most recent call last):
...
ValueError: Matrix rows can only contain letters and numbers.
>>> validate_matrix_content(['aaa', 'aaa', 'aaaa'], 3)
Traceback (most recent call last):
...
ValueError: Each row in the matrix must have exactly 3 characters.
"""
print(matrix)
if len(matrix) != size:
raise ValueError("The matrix dont match with size.")
for row in matrix:
if len(row) != size:
msg = f"Each row in the matrix must have exactly {size} characters."
raise ValueError(msg)
if not all(char.isalnum() for char in row):
raise ValueError("Matrix rows can only contain letters and numbers.")
def validate_moves(moves: list[tuple[int, int]], size: int) -> None:
"""
>>> validate_moves([(1, 2), (-1, 0)], 3)
Traceback (most recent call last):
...
ValueError: Move is out of bounds for a matrix.
"""
for move in moves:
x, y = move
if not (0 <= x < size and 0 <= y < size):
raise ValueError("Move is out of bounds for a matrix.")
def parse_moves(input_str: str) -> list[tuple[int, int]]:View on GitHub (pinned to f5988cc097)
Solutions
- Make every row string exactly 'size' characters long.
When it happens
Trigger: Thrown at matrix/matrix_based_game.py:87 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/a5ed87c633f81185.
Report an issue: GitHub.