TheAlgorithms/Python · error · TypeError

Invalid velocity. Should be an integer or float.

Error message

Invalid velocity. Should be an integer or float.

What it means

Error "Invalid velocity. Should be an integer or float." thrown in TheAlgorithms/Python.

Source

Thrown at physics/horizontal_projectile_motion.py:34

For more info: https://en.wikipedia.org/wiki/Projectile_motion
"""

# Importing packages
from math import radians as deg_to_rad
from math import sin

# Acceleration Constant on Earth (unit m/s^2)
g = 9.80665


def check_args(init_velocity: float, angle: float) -> None:
    """
    Check that the arguments are valid
    """

    # Ensure valid instance
    if not isinstance(init_velocity, (int, float)):
        raise TypeError("Invalid velocity. Should be an integer or float.")

    if not isinstance(angle, (int, float)):
        raise TypeError("Invalid angle. Should be an integer or float.")

    # Ensure valid angle
    if angle > 90 or angle < 1:
        raise ValueError("Invalid angle. Range is 1-90 degrees.")

    # Ensure valid velocity
    if init_velocity < 0:
        raise ValueError("Invalid velocity. Should be a positive number.")


def horizontal_distance(init_velocity: float, angle: float) -> float:
    r"""
    Returns the horizontal distance that the object cover

    Formula:

View on GitHub (pinned to f5988cc097)

Solutions

  1. Pass the velocity as an int or float.

When it happens

Trigger: Thrown at physics/horizontal_projectile_motion.py:34 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/bdf9364f1f1ca140. Report an issue: GitHub.