DEV Community

Cover image for Codewars Python — Integer to Roman conversion
He Codes IT
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.
To Find the Solution Read
https://hecodesit.com/codewars-python-integer-to-roman-conversion/

Top comments (6)

Collapse
 
netosimoes profile image
NetoSimoes

I came up with this solution

Collapse
 
netosimoes profile image
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

Collapse
 
hecodesit profile image
He Codes IT

Really Helpful

Collapse
 
hecodesit profile image
He Codes IT

Hey, Thank You so Much, Just read about this function, will apply in future.

Collapse
 
jonrandy profile image
Jon Randy 🎖️

Why does you image say "1, 2, 3, 4, 5, 6, 8, 8, 9, 10, 11, 12" ?

Collapse
 
hecodesit profile image
He Codes IT

It was a Codewar Kata to Convert Integers into Roman Numbers in Python