DEV Community

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

Posted on

3

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

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay