Title: Roman numerals are derived from the ancient Roman coding system. They are based on the combination of a particular letter of the alphabet, and the number represented is equal to the number of these numbers (or subtract). The top ten Roman numerals are: I,ii,iii,iv,v,vi,vii,viii,ix and X. The Roman notation system is not directly based on the decimal, it has no zeros. Roman numerals are based on the combination of these seven symbols: symbolic value i 1 (unus) v 5 (quinque) x 10 (DECEM) l 50 ( Quinquaginta) c 100 (centum) d 500 (Quingenti) m 1,000 (Mille) additional information about the Roman numerals can be found in Wikipedia article. In this task, you should return a Roman number with a range from 1 to 3999 for the specified integer value. Enter: an integer (int). Output: A string representation of Roman numerals (str). Prerequisite: 0 < number < 4000 test data: 6764993888 correct result: VILXXVICDXCIXMMMDCCCLXXXVIII problem-solving ideas: The number from large to small split, need to grasp the law, in turn, the results are saved to the list, and finally printed out. Script: Def operate (DATA,&NBSP;DIVISOR,&NBSP;STR1,&NBSP;STR2,&NBSP;STR3): result = ' temp = data // divisor if temp : if temp >= 5: if temp == 9: result = str1 + str3 temp -= 9 else: result = str2 temp -= 5 if temp: if temp == 4: result += str1 + str2 else: result += str1 * temp return resultdef checkio (data): result = [] temp = data // 1000 if temp: result.append (' M ' * temp) data %= 1000 temp = operate (data, 100, ' C ', ' D ', ' M ') if temp: result.append (temp) data %= 100 temp = operate (data , 10, ' X ', ' L ', ' C ') if temp: result.append (temp) data %= 10 temp = operate (data, 1, ' I ', ' V ', ' X ') if temp: result.append (temp) return '. Join ( Result
This article is from the "Last Night Stars" blog, please make sure to keep this source http://yestreenstars.blog.51cto.com/1836303/1661691
Arabic numerals converted to Roman numerals