Browse Source

added working roman example

master
Stephen McQuay 8 years ago
parent
commit
1894bb160c
2 changed files with 21 additions and 0 deletions
  1. +16
    -0
      roman/roman.py
  2. +5
    -0
      roman/stdin1.txt

+ 16
- 0
roman/roman.py View File

@ -0,0 +1,16 @@
import sys
def int_to_roman(input):
ints = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
nums = ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV',
'I')
result = ""
for i in range(len(ints)):
count = int(input / ints[i])
result += nums[i] * count
input -= ints[i] * count
return result
for num in [int(i.strip()) for i in sys.stdin]:
print int_to_roman(num)

+ 5
- 0
roman/stdin1.txt View File

@ -0,0 +1,5 @@
2006
1944
1910
800
42

Loading…
Cancel
Save