Skip to content

Fix IndexError, input validation, and enhance Converting_Roman_to_Integer #475

Description

@Prayas340

Description

The Converting_Roman_to_Integer script has several usability bugs, unhandled exceptions, and missing features:

  1. Unhandled IndexError: Running python Converting_Roman_to_Integer.py with no CLI arguments throws an unhandled IndexError: list index out of range on sys.argv[1].
  2. Case Sensitivity & Whitespace Failures: Providing lowercase Roman numerals (xiv) or inputs with whitespace causes unhandled KeyError crashes.
  3. No Syntax / Character Validation: Non-Roman characters (ABC, 123) or invalid combinations (IIII, VV, IC) result in crashes or invalid numbers without informative error messages.
  4. Shadowing Built-in Identifier: The script defines dict = {...}, shadowing Python's built-in dict type.
  5. No Modular Structure: Logic is placed at module top-level without reusable functions or if __name__ == '__main__': guards.
  6. Incomplete README: README.md is minimal (3 lines) and does not adhere to README_TEMPLATE.md.

Type of issue

  • Bug
  • Documentation
  • Feature (Enhanced Script / Unit Tests)

Checklist:

  • I have read the project guidelines.

  • I have checked previous issues to avoid duplicates.

  • This issue will be meaningful for the project.

  • I have added steps to reproduce the bug:

    1. Run python Converting_Roman_to_Integer/Converting_Roman_to_Integer.py without arguments -> Crashes with IndexError.
    2. Run python Converting_Roman_to_Integer/Converting_Roman_to_Integer.py xiv -> Crashes with KeyError.
    3. Run python Converting_Roman_to_Integer/Converting_Roman_to_Integer.py IIII -> Incorrectly prints 4 without validation error.
  • I have proposed a possible solution for the bug:

    • Add input sanitization (.strip().upper()) and regex syntax validation.
    • Support both CLI arguments and interactive fallback prompt.
    • Implement reusable functions roman_to_int(roman) and int_to_roman(num).
    • Add a comprehensive unit test suite and update README.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions