TheAlgorithms/Python · error · ValueError
Matrix rows can only contain letters and numbers.
Error message
Matrix rows can only contain letters and numbers.
What it means
Error "Matrix rows can only contain letters and numbers." thrown in TheAlgorithms/Python.
Source
Thrown at matrix/matrix_based_game.py:89
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]]:
"""
>>> parse_moves("0 1, 1 1")View on GitHub (pinned to f5988cc097)
Solutions
- Use only alphanumeric characters in matrix rows.
When it happens
Trigger: Thrown at matrix/matrix_based_game.py:89 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/1847c75686ed2e8e.
Report an issue: GitHub.