the code works in external ide, but not in checkio
I would like to give some feedback about ...
From: http://www.checkio.org/mission/roman-numerals/solve/
HTTP\_USER\_AGENT:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36
My Code:
def checkio(data):
numerals = {'M' : 1000, 'D': 500, 'C' : 100, 'L': 50, 'X': 10, 'V': 5, 'I': 1}
end_result = ""
new_result = ""
for key in numerals:
while True:
new_result, data, flag = check(data, key, numerals[key])
if not flag:
break
else:
end_result += new_result
return end_result
def check(data, key, value):
result = ""
flag = True
if data - value >= 0:
result += key
data -= value
else:
flag = False
return result, data, flag
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(6) == 'VI', '6'
assert checkio(76) == 'LXXVI', '76'
assert checkio(499) == 'CDXCIX', '499'
assert checkio(3888) == 'MMMDCCCLXXXVIII', '3888'
Created at: 2014/07/17 13:49; Updated at: 2014/07/17 19:54