TheAlgorithms/Python · error · ValueError
The word parameter should be a string of length greater than
Error message
The word parameter should be a string of length greater than 0.
What it means
Raised by doppler_effect() in physics/doppler_frequency.py when the computed observed frequency is <= 0. With f = f0*(v + v0)/(v - vs), a non-positive result means the numerator or denominator flipped sign: the source outruns the wave toward the observer (vs > v) or the observer recedes faster than the wave propagates (v0 < -v with the source behind). Physically the simple Doppler formula has broken down, so the library refuses the value.
Source
Thrown at backtracking/word_search.py:144
board_error_message = (
"The board should be a non empty matrix of single chars strings."
)
len_board = len(board)
if not isinstance(board, list) or len(board) == 0:
raise ValueError(board_error_message)
for row in board:
if not isinstance(row, list) or len(row) == 0:
raise ValueError(board_error_message)
for item in row:
if not isinstance(item, str) or len(item) != 1:
raise ValueError(board_error_message)
# Validate word
if not isinstance(word, str) or len(word) == 0:
raise ValueError(
"The word parameter should be a string of length greater than 0."
)
len_board_column = len(board[0])
for i in range(len_board):
for j in range(len_board_column):
if exits_word(
board, word, i, j, 0, {get_point_key(len_board, len_board_column, i, j)}
):
return True
return False
if __name__ == "__main__":
import doctest
doctest.testmod()View on GitHub (pinned to f5988cc097)
Solutions
- Check the sign convention: obs_vel + toward source, src_vel + toward observer; verify your signs before calling.
- Reject or special-case inputs where src_vel > wave_vel or obs_vel < -wave_vel (supersonic regimes need shock physics, not this formula).
- Catch ValueError and flag the input pair as out of model range.
Example fix
# before
f = doppler_effect(100, 330, 10, 340) # supersonic source -> ValueError
# after
if src_vel >= wave_vel or obs_vel <= -wave_vel:
raise ValueError("supersonic regime: Doppler formula invalid")
f = doppler_effect(100, 330, 10, src_vel) Defensive patterns
Strategy: validation
Validate before calling
if src_vel > wave_vel or obs_vel < -wave_vel:
raise ValueError("supersonic regime outside Doppler model")
f = doppler_effect(org_freq, wave_vel, obs_vel, src_vel) Try / catch
try:
f = doppler_effect(f0, v, v0, vs)
except ValueError as e:
if "Non-positive frequency" in str(e):
sign_hint = 'src_vel too large' if vs > v else 'obs_vel too negative (sign convention?)'
raise ValueError(sign_hint) from e
raise Prevention
- obs_vel positive = toward source; src_vel positive = toward observer — recheck signs.
- Reject supersonic inputs before the call.
- Compute the expected sign of (v + v0) and (v - vs) in debug logs when tuning.
When it happens
Trigger: doppler_effect(100, 330, 10, 340): source at 340 m/s > 330 m/s wave speed. doppler_effect(100, 330, -340, 10): observer receding at 340 m/s > wave speed. Any supersonic closing speed or observer receding faster than v.
Common situations: Supersonic aircraft / Mach > 1 simulations where the classical Doppler formula does not apply; sign-convention mistakes — obs_vel is positive when moving toward the source, src_vel positive when moving toward the observer, and swapped signs can flip the result negative.
Related errors
- Input value must be a positive integer
- Impossible fluid density
- Impossible bulk modulus
- Expected a_coeffs to have {self.order + 1} elements for {sel
- Expected b_coeffs to have {self.order + 1} elements for {sel
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/4a530142437de45d.
Report an issue: GitHub.