Skip to content

Instantly share code, notes, and snippets.

@gizemiskender
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save gizemiskender/9722534 to your computer and use it in GitHub Desktop.

Select an option

Save gizemiskender/9722534 to your computer and use it in GitHub Desktop.
Romen Numbers
roman = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
romanDict = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
def int_to_roman(strnumber):
result = ""
number = int(strnumber)
for i, v in enumerate(values):
while (number >= v):
number -= v
result += roman[i]
return result
def roman_to_int(s):
sum = 0
while s:
if len(s) == 1:
sum += romanDict[s[0]]
break
if romanDict[s[0]] >= romanDict[s[1]]:
sum += romanDict[s[0]]
s = s[1:]
else:
sum += romanDict[s[1]] - romanDict[s[0]]
s = s[2:]
return sum
for k in range(1,51): # ilk 50 sayi ve roman degerleri
print str(roman_to_int(int_to_roman(k))) + " ---> " + int_to_roman(k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment