I have noticed I get an error TypeError, when trying to pass through an argument in the terminal when using the click package. What is strange is this does not occur when running my application in the web browser.
Here is the error:
Traceback (most recent call last):
File "C:\Users\XYZ-J\dev\repos\roman_2\to_roman_numeral_converter.py", line 37, in <module>
print(to_roman_numeral(to_roman_numeral_cli))
File "C:\Users\XYZ-J\dev\repos\roman_2\to_roman_numeral_converter.py", line 22, in to_roman_numeral
if arabic_number // value:
TypeError: unsupported operand type(s) for //: 'Command' and 'int'
And here is the program itself
def to_arabic_number(roman):
# largest to smallest- add them up
# smallest to largest- minus them
roman_table = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}
result = 0
for numeral in range(len(roman)):
if (
numeral + 1 < len(roman)
and roman_table[roman[numeral]] < roman_table[roman[numeral + 1]]
):
result -= roman_table[roman[numeral]]
else:
result += roman_table[roman[numeral]]
return result
@click.command()
# @click.argument("roman_numeral")
@click.option("--roman", prompt="Roman numeral to convert please", type=str)
def to_arabic_number_cli(roman):
return to_arabic_number(roman)
if __name__ == "__main__":
to_arabic_number_cli()
print(to_arabic_number(to_arabic_number_cli))
What I think is the issue is:
- arabic_number is an integer (I have tried changing it into str)
- Parsing the function into the to_arabic_function?
Any help here would be great!