8000 New feature: Support for converting numbers in a larger range. by lighting9999 · Pull Request #12576 · TheAlgorithms/Python · GitHub
[go: up one dir, main page]

Skip to content

New feature: Support for converting numbers in a larger range. #12576

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

Closed
wants to merge 21 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5de6f72
New feature: Support for converting numbers in a larger range.
lighting9999 Feb 10, 2025
1e48591
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2025
f5cdd52
Update roman_numerals.py
lighting9999 Feb 10, 2025
eb8598f
Update roman_numerals.py
lighting9999 Feb 10, 2025
ad28671
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2025
8499e59
Update roman_numerals.py
lighting9999 Feb 10, 2025
99a081b
Update roman_numerals.py
lighting9999 Feb 10, 2025
bcfd98c
Update roman_numerals.py
lighting9999 Feb 10, 2025
1735aed
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2025
6bff121
Update roman_numerals.py
lighting9999 Feb 10, 2025
dd13fe2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2025
8b10293
Update roman_numerals.py
lighting9999 Feb 10, 2025
5e41453
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2025
657073d
Update roman_numerals.py
lighting9999 Feb 10, 2025
da299d4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2025
ba43420
Update roman_numerals.py
lighting9999 Feb 10, 2025
e6ea0ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2025
07721a8
Update roman_numerals.py
lighting9999 Feb 10, 2025
668b78a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2025
f4682f1
Update roman_numerals.py
lighting9999 Feb 10, 2025
30a49b3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 10, 2025
commit dd13fe23b057b0df71c996fa5b466c3ecaae4bfb
12 changes: 9 additions & 3 deletions conversions/roman_numerals.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
(4, "IV"),
(1, "I"),
]


def roman_to_int(roman: str) -> int:
"""
Convert a Roman numeral to an integer, supporting Vinculum notation
Expand All @@ -45,13 +47,15 @@ def roman_to_int(roman: str) -> int:
i, total = 0, 0
while i < len(roman):
# Check for 2-character symbols first (like I_ or X_)
if i + 1 < len(roman) and roman[i:i+2] in vals:
total += vals[roman[i:i+2]]
if i + 1 < len(roman) and roman[i : i + 2] in vals:
total += vals[roman[i : i + 2]]
i += 2
else:
total += vals[roman[i]]
i += 1
return total


def int_to_roman(number: int) -> str:
"""
Convert an integer to a Roman numeral, supporting Vinculum notation
Expand All @@ -74,7 +78,9 @@ def int_to_roman(number: int) -> str:
if number == 0:
break
return "".join(result)



if __name__ == "__main__":
import doctest

doctest.testmod()
Loading
0