본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 106

반응형

Q>

Stephen's speech module is broken.

(스티븐의 연설 모듈이 고장났다.)

This module is responsible for his number pronunciation.

(이 모듈은 그의 번호 발음을 담당합니다.)

He has to click to input all of the numerical digits in a figure, so when there are big numbers it can take him a long time.

(그는 숫자의 모든 숫자를 입력하기 위해 클릭해야하므로 숫자가 클 때 시간이 오래 걸릴 수 있습니다.)

Help the robot to speak properly and increase his number processing speed by writing a new speech module for him.

(로봇이 적절하게 말하고 새로운 스피치 모듈을 작성하여 번호 처리 속도를 높이도록 도와줍니다.)

All the words in the string must be separated by exactly one space character.

(문자열의 모든 단어는 정확히 하나의 공백 문자로 구분되어야합니다.)

Be careful with spaces -- it's hard to see if you place two spaces instead one.

(공백을주의하십시오. 공백 대신 공백 두 개를 배치하는 것이 쉽지 않습니다.)

 

Input: A number as an integer.

        (정수로 나타낸 숫자.)

 

Output: The string representation of the number as a string.

           (숫자로 된 문자열 표현입니다.)

 

Example:

checkio(4)=='four'
checkio(143)=='one hundred forty three'
checkio(12)=='twelve'
checkio(101)=='one hundred one'
checkio(212)=='two hundred twelve'
checkio(40)=='forty'

 

How it is used: This concept may be useful for the speech synthesis software or automatic reports systems.

                     (이 개념은 음성 합성 소프트웨어 또는 자동 보고서 시스템에 유용 할 수 있습니다.)

                     This system can also be used when writing a chatbot by assigning words or phrases numerical

                     (이 시스템은 단어 또는 구를 할당하여 챠트 봇을 작성할 때도 사용할 수 있습니다.)

                     values and having a system retrieve responses based on those values.

                     (값을 기반으로 응답을 검색하는 시스템)

 

Precondition: 0 < number < 1000

 

A>

FIRST_TEN = ["one", "two", "three", "four", "five", "six", "seven",
             "eight", "nine"]
SECOND_TEN = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
              "sixteen", "seventeen", "eighteen", "nineteen"]
OTHER_TENS = ["twenty", "thirty", "forty", "fifty", "sixty", "seventy",
              "eighty", "ninety"]
HUNDRED = "hundred"

def checkio(number):
    answer = ''
    remainded = 0 + number

    if remainded > 99:
        answer += FIRST_TEN[remainded // 100 - 1] + ' ' + HUNDRED + ' '
        remainded = remainded % 100
    if remainded > 19:
        answer += OTHER_TENS[remainded // 10 - 2] + ' '
        remainded = remainded % 10
    if remainded > 9:
        answer += SECOND_TEN[remainded % 10]
    elif remainded > 0:
        answer += FIRST_TEN[remainded - 1]
    return answer.rstrip()

if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert checkio(4) == 'four', "1st example"
    assert checkio(133) == 'one hundred thirty three', "2nd example"
    assert checkio(12) == 'twelve', "3rd example"
    assert checkio(101) == 'one hundred one', "4th example"
    assert checkio(212) == 'two hundred twelve', "5th example"
    assert checkio(40) == 'forty', "6th example"
    assert not checkio(212).endswith(' '), "Don't forget strip whitespaces at the end of string"
    print('Done! Go and Check it!')

 

O>

Done! Go and Check it!

Process finished with exit code 0

 

S>

https://py.checkio.org

반응형

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

Python Learn the basics Quiz 108  (0) 2019.06.27
Python Learn the basics Quiz 107  (0) 2019.06.27
Python Learn the basics Quiz 105  (0) 2019.06.25
Python Learn the basics Quiz 104  (0) 2019.06.25
Python Learn the basics Quiz 103  (0) 2019.06.25