본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 66

반응형

Q>

Roman numerals come from the ancient Roman numbering system.

(로마 숫자는 고대 로마 넘버링 시스템에서 왔습니다.)

They are based on specific letters of the alphabet which are combined to signify the sum (or, in some cases, the difference) of their values.

(그들은 알파벳의 특정 문자를 기반으로하여 그 값의 합 (또는 어떤 경우에는 차이)을 나타냅니다)

The first ten Roman numerals are:

(처음 10 개의 로마 숫자는 다음과 같습니다.)

I, II, III, IV, V, VI, VII, VIII, IX, and X.

The Roman numeral system is decimal based but not directly positional and does not include a zero.

(로마 숫자 시스템은 10 진수 기반이지만 직접 위치가 아니며 0을 포함하지 않습니다.)

Roman numerals are based on combinations of these seven symbols:

(로마 숫자는이 7 개의 상징의 조합에 기초를 둔다 :)

NumeralValue

I 1 (unus)
V 5 (quinque)
X 10 (decem)
L 50 (quinquaginta)
C 100 (centum)
D 500 (quingenti)
M 1,000 (mille)

More additional information about roman numerals can be found on the Wikipedia article.

(로마 숫자에 대한 추가 정보는 Wikipedia 기사에서 찾을 수 있습니다.)

For this task, you should return a roman numeral using the specified integer value ranging from 1 to 3999.

(이 작업을 수행하려면 1에서 3999까지의 지정된 정수 값을 사용하여 로마 숫자를 반환해야합니다.)

 

Input: A number as an integer.

         (정수로 나타낸 숫자.)

 

Output: The Roman numeral as a string.

           (로마 숫자를 문자열로 사용합니다.)

 

Example:

checkio(6) == 'VI'
checkio(76) == 'LXXVI'
checkio(13) == 'XIII'
checkio(44) == 'XLIV'
checkio(3999) == 'MMMCMXCIX'

 

How it is used: This is an educational task that allows you to explore different numbering systems.

                     (교육 과정으로 다른 번호 체계를 탐색 할 수 있습니다.)

                     Since roman numerals are often used in the typography, it can alternatively be used for text                                 generation.

                     (로마 숫자는 타이포그래피에서 자주 사용되기 때문에 텍스트 생성에 로마 숫자가 사용됩니다.)

                     The year of construction on building faces and cornerstones is most often written by Roman

                     numerals.

                     (건물면과 기초석의 건축 년도는 로마 숫자로 작성되는 경우가 가장 많습니다.)

                     These numerals have many other uses in the modern world and you read about it here... 

                     (이 숫자는 현대 세계에서 많은 다른 용도로 사용되며 여기에서 읽습니다)

                     Or maybe you will have a customer from Ancient Rome ;-)

                     (아니면 고대 로마의 고객이있을 것입니다 ;-))

 

Precondition: 0 < number < 4000

 

A>

"""
Numeral	Value
I	1 (unus)
V	5 (quinque)
X	10 (decem)
L	50 (quinquaginta)
C	100 (centum)
D	500 (quingenti)
M	1,000 (mille)
"""
def checkio(data):

    #replace this for solution
    str = ''
    while data // 1000 != 0:
        data -= 1000
        str += 'M'
    while data // 500 != 0:
        data -= 500
        str += 'D'
    while data // 100 != 0:
        data -= 100
        str += 'C'
    while data // 50 != 0:
        data -= 50
        str += 'L'
    while data // 10 != 0:
        data -= 10
        str += 'X'
    while  data // 5 != 0:
        data -= 5
        str += 'V'
    str += ('I' * data)
    str = str.replace('DCCCC', 'CM')    # 900
    str = str.replace('CCCC', 'CD')     # 400
    str = str.replace('LXXXX', 'XC')    # 90
    str = str.replace('XXXX', 'XL')     # 40
    str = str.replace('VIIII', 'IX')    # 9
    str = str.replace('IIII', 'IV')     # 4
    # print('str=', str)
    return str

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'
    print('Done! Go Check!')

 

O>

Done! Go Check!

Process finished with exit code 0

 

S>

https://py.checkio.org

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 68  (0) 2019.06.15
Python Learn the basics Quiz 67  (0) 2019.06.14
Python Learn the basics Quiz 65  (0) 2019.06.14
Python Learn the basics Quiz 64  (0) 2019.06.14
Python Learn the basics Quiz 63  (0) 2019.06.14