checkio-speech module
来源:互联网 发布:青岛知行国际派遣公司 编辑:程序博客网 时间:2024/06/05 10:07
史蒂芬的语音模块坏了。该模块是负责他的数字发音的。他必须点击输入所有数字,因此当有大数字就要花费他很长的时间来输入。为他写一个新的语音模块帮助机器人正常说话并且增加他的数字的处理速度。字符串中的所有单词必须以一个空格字符分隔。请小心使用空格 – 如果你把两个空格当做一个,那是很难看到的。
输入: 作为整数(int)的一个数字。
输出: 代表数字的字符串。(str)
范例:
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’
前提: 0 < number < 1000
FIRST_TEN = ["zero", "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): sayit = [] if number >= 100: sayit.append(FIRST_TEN[number//100]) sayit.append(HUNDRED) number %= 100 if number >= 20: sayit.append(OTHER_TENS[number//10-2]) number %= 10 if number >= 10: sayit.append(SECOND_TEN[number-10]) elif number > 0 or words == []: sayit.append(FIRST_TEN[number]) return ' '.join(sayit)#These "asserts" using only for self-checking and not necessary for auto-testingif __name__ == '__main__': 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 checkio(400) == 'four hundred', "7th example" assert not checkio(212).endswith(' '), "Don't forget strip whitespaces at the end of string"
把最后要打印的字符串用一个列表存储。判断是否大于100,是的话就append百位数字加hundred。然后把number%100取余数,在判断十位和个位。如果大于20在OTHER_TENS里面。否则找另外一个列表。
0 0
- checkio-speech module
- Python checkio "Speech Module"解决方案
- speech module
- checkio的一些题:Speech Module,Feed Pigeons,Roman numerals,Golden Pyramid,The Most Numbers,Digits Multipl
- checkio--
- Speech
- SPEECH
- checkio (Brackets)
- Python Checkio
- Checkio--Friends
- checkio-medium
- CheckIO 中位数
- checkio (Determine the order)
- checkio (Numbers Factory)
- checkio (How much gold)
- checkio (Counting tiles)
- checkio (URL Normalization)
- checkio (water jars)
- Cpp--关于windows.h头文件
- Android 各大网络请求库的比较及实战
- Android 仿美团网,探索ListView的A-Z字母排序功能实现选择城市
- Java中Synchronized的用法
- cvpr2015papers
- checkio-speech module
- 老罗Android(19)AsyncTask下载图片例子
- CSDN修改头像(最新)
- 【论】提示消息的幽默性
- Javascript异步编程的4种方法
- 使用Github Pages建独立博客
- IOS 第三方库----常用第三方库
- 大数据量数据库优化
- SQL Server导入数据报错"无法在只读列“Id”中插入数据"