TheAlgorithms/Python · error · ValueError
No particles provided
Error message
No particles provided
What it means
Error "No particles provided" thrown in TheAlgorithms/Python.
Source
Thrown at physics/center_of_mass.py:88
...
ValueError: Mass of all particles must be greater than 0
>>> center_of_mass([
... Particle(1, 2, 3, 0),
... Particle(5, 6, 7, 8),
... Particle(9, 10, 11, 12)
... ])
Traceback (most recent call last):
...
ValueError: Mass of all particles must be greater than 0
>>> center_of_mass([])
Traceback (most recent call last):
...
ValueError: No particles provided
"""
if not particles:
raise ValueError("No particles provided")
if any(particle.mass <= 0 for particle in particles):
raise ValueError("Mass of all particles must be greater than 0")
total_mass = sum(particle.mass for particle in particles)
center_of_mass_x = round(
sum(particle.x * particle.mass for particle in particles) / total_mass, 2
)
center_of_mass_y = round(
sum(particle.y * particle.mass for particle in particles) / total_mass, 2
)
center_of_mass_z = round(
sum(particle.z * particle.mass for particle in particles) / total_mass, 2
)
return Coord3D(center_of_mass_x, center_of_mass_y, center_of_mass_z)
View on GitHub (pinned to f5988cc097)
Solutions
- Provide at least one particle.
When it happens
Trigger: Thrown at physics/center_of_mass.py:88 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/bf318a3fc4901fbb.
Report an issue: GitHub.