DEV Community is a community of 851,084 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

He Codes IT

Posted on

Codewars Python — Integer to Roman conversion

Codewars Python in its 6kyu Kata has given us a problem to convert an integer into the Roman numeral Symbols. In Ancient Roman times, people use Roman numbers instead of integers.
My approach to the Problem:
Firstly, I made two Lists in Python, first to store the Numbers which have a Single Roman Symbol Available and Second List for Roman Symbols.
https://hecodesit.com/codewars-python-integer-to-roman-conversion/

Discussion (7)

NetoSimoes

I came up with this solution

NetoSimoes

from enum import Enum

class Roman(Enum):
M = 1000
D = 500
C = 100
L = 50
X = 10
V = 5
I = 1

def convert_number_to_roman(number: int) -> str:
result = ""
while number > 0:
for roman in Roman:
while number - roman.value >= 0:
number -= roman.value
result += roman.name
return result

He Codes IT

Pavel Morava

From a short glance on your code, I wonder if you considered usage of Python built-in divmod.

``````integer, modulus = divmod(11,3)
``````
He Codes IT