TheAlgorithms/Python · error · ZeroDivisionError
Division by zero implies vs=v and observer in front of the s
Error message
Division by zero implies vs=v and observer in front of the source
What it means
Error "Division by zero implies vs=v and observer in front of the source" thrown in TheAlgorithms/Python.
Source
Thrown at physics/doppler_frequency.py:90
106.25
>>> doppler_effect(100, 330, -10, -10) # source and observer moving away
94.11764705882354
>>> doppler_effect(100, 330, 10, 330) # source moving at same speed as the wave
Traceback (most recent call last):
...
ZeroDivisionError: Division by zero implies vs=v and observer in front of the source
>>> doppler_effect(100, 330, 10, 340) # source moving faster than the wave
Traceback (most recent call last):
...
ValueError: Non-positive frequency implies vs>v or v0>v (in the opposite direction)
>>> doppler_effect(100, 330, -340, 10) # observer moving faster than the wave
Traceback (most recent call last):
...
ValueError: Non-positive frequency implies vs>v or v0>v (in the opposite direction)
"""
if wave_vel == src_vel:
raise ZeroDivisionError(
"Division by zero implies vs=v and observer in front of the source"
)
doppler_freq = (org_freq * (wave_vel + obs_vel)) / (wave_vel - src_vel)
if doppler_freq <= 0:
raise ValueError(
"Non-positive frequency implies vs>v or v0>v (in the opposite direction)"
)
return doppler_freq
if __name__ == "__main__":
import doctest
doctest.testmod()
View on GitHub (pinned to f5988cc097)
Solutions
- Avoid source velocity equal to wave velocity; use vs < v.
When it happens
Trigger: Thrown at physics/doppler_frequency.py:90 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/d68804e38d511845.
Report an issue: GitHub.