added working roman example

This commit is contained in:
Stephen McQuay 2012-09-08 11:44:13 -06:00
parent b7795a2938
commit 1894bb160c
2 changed files with 21 additions and 0 deletions

16
roman/roman.py Normal file
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
roman/stdin1.txt Normal file
View File

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