Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Support numbers such as "IV" #43

Open
NightMachinery opened this issue Feb 19, 2021 · 1 comment
Open

[FR] Support numbers such as "IV" #43

NightMachinery opened this issue Feb 19, 2021 · 1 comment

Comments

@NightMachinery
Copy link

Support numbers such as IV (4), II (2), etc.

@gweber2
Copy link

gweber2 commented Jan 5, 2023

found this on the web for roman numbers:

def roman_to_int(s):
rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
int_val = 0
for i in range(len(s)):
if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]:
int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]]
else:
int_val += rom_val[s[i]]
return int_val

Edit: The function seems to work but gives wrong output instead of error when given a wrong roman number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants