TheAlgorithms/Python · error · ValueError

No input value was provided

Error message

No input value was provided

What it means

Raised by decimal_to_binary_recursive(number) in conversions/decimal_to_binary.py:96 when, after str(number).strip(), the value is empty. The function's contract is to stringify whatever it receives, so an empty string, a blank string, or None-adjacent empty input means there is no number to convert and it fails fast with a ValueError.

Source

Thrown at conversions/decimal_to_binary.py:96

    for positive and negative integers respectively.
    >>> decimal_to_binary_recursive(0)
    '0b0'
    >>> decimal_to_binary_recursive(40)
    '0b101000'
    >>> decimal_to_binary_recursive(-40)
    '-0b101000'
    >>> decimal_to_binary_recursive(40.8)
    Traceback (most recent call last):
        ...
    ValueError: Input value is not an integer
    >>> decimal_to_binary_recursive("forty")
    Traceback (most recent call last):
        ...
    ValueError: Input value is not an integer
    """
    number = str(number).strip()
    if not number:
        raise ValueError("No input value was provided")
    negative = "-" if number.startswith("-") else ""
    number = number.lstrip("-")
    if not number.isnumeric():
        raise ValueError("Input value is not an integer")
    return f"{negative}0b{decimal_to_binary_recursive_helper(int(number))}"


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    print(decimal_to_binary_recursive(input("Input a decimal number: ")))

View on GitHub (pinned to f5988cc097)

Solutions

  1. Check for blank input before calling: if not str(value).strip(): handle the empty case in your UI/logic
  2. Provide a default: value = value.strip() or '0'
  3. Wrap interactive input in a loop that re-prompts until non-empty

Example fix

# before
print(decimal_to_binary_recursive(input('num: ')))  # Enter -> ValueError

# after
raw = input('num: ').strip()
if not raw:
    raise SystemExit('a number is required')
print(decimal_to_binary_recursive(raw))
Defensive patterns

Strategy: validation

Validate before calling

if not str(number).strip():
    raise ValueError('a decimal number is required')

Try / catch

try:
    decimal_to_binary_recursive(number)
except ValueError as e:
    if 'No input value' in str(e):
        number = '0'  # or re-prompt
    else:
        raise

Prevention

When it happens

Trigger: decimal_to_binary_recursive(''), decimal_to_binary_recursive(' '), or passing an empty form field / blank CLI input / empty environment variable.

Common situations: The module's own __main__ block calls decimal_to_binary_recursive(input(...)) — pressing Enter on an empty prompt triggers exactly this; web forms where a numeric field was left blank.

Related errors


AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14). Data as JSON: /api/errors/d38f5979262306aa. Report an issue: GitHub.