Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Roman Numerals by bartosz_lyzwa
def generate(num,symbols):
if(num>0):
roman=''
if(num==9):
roman=symbols[0]+symbols[2]
elif(num>=5):
roman+=symbols[1]
for i in range(num-5):
roman+=symbols[0]
elif(num==4):
roman+=symbols[0]+symbols[1]
elif(num<4):
for i in range(num):
roman+=symbols[0]
return roman
else:
return ''
def checkio(data):
thousands=int(data/1000)
hundreds=int((data-(thousands*1000))/100)
tens=int((data-(thousands*1000)-(hundreds*100))/10)
units=int(data-(thousands*1000)-(hundreds*100)-(tens*10))
print(thousands,'|',hundreds,'|',tens,'|',units)
return thousands*'M'+generate(hundreds,['C','D','M'])+generate(tens,['X','L','C'])+generate(units,['I','V','X'])
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(587) == 'VI', '6'
Oct. 21, 2017