DEV Community

Cover image for Codewars Python — Integer to Roman conversion
YTTMP3
YTTMP3

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
 
ytt-mp3 profile image
YTTMP3

Really Helpful

Collapse
 
ytt-mp3 profile image
YTTMP3

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
 
ytt-mp3 profile image
YTTMP3

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