Click is not responding as expected- I am trying to parse through an argument to convert a roman numeral to an integer?

Viewed 9

Prior to using click when I manually inputted an argument my code worked fine as expected. However, I have been following various videos online to implement click and getting a strange result. See below:

 python to_roman_numeral_converter.py
Roman numeral to convert please: V
Usage: to_roman_numeral_converter.py [OPTIONS] ROMAN_NUMERAL
Try 'to_roman_numeral_converter.py --help' for help.

Error: Got unexpected extra arguments (o m a n _ n u m e r a l)

Also when I run the script I don't have the ability to --help, it runs straight to the part I need to input an integer.

import click


@click.command()
@click.argument("roman_numeral")
@click.option("--roman", prompt="Roman numeral to convert please", type=str)
def to_arabic_number(roman_numeral) -> int:
    roman_table = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}
    result = 0

    for numeral in range(len(roman_numeral)):
        if (
            numeral + 1 < len(roman_numeral)
            and roman_table[roman_numeral[numeral]]
            < roman_table[roman_numeral[numeral + 1]]
        ):
            result -= roman_table[roman_numeral[numeral]]
        else:
            result += roman_table[roman_numeral[numeral]]

    return result
if __name__ == "__main__":
    # to_roman_numeral()
    print(to_arabic_number("roman_numeral"))

1.In short, appending nothing I expect to see an option list 2. --help should list some options 3. --roman V should output 5

Any help here with an explanation would be appreciated.

0 Answers
Related