Chinaunix首页 | 论坛 | 博客
  • 博客访问: 502730
  • 博文数量: 58
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 647
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-09 17:06
文章分类
文章存档

2020年(4)

2019年(54)

我的朋友

分类: Python/Ruby

2019-12-17 14:43:03


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):

    if number >= 0 and number < 10:

        english = FIRST_TEN[number - 1]

        return english

    elif number >= 10 and number < 20:

        english = SECOND_TEN[number - 10]

        return english

    elif number >= 20 and number < 100:

        if number % 10 == 0:

            english = OTHER_TENS[number // 10 - 2]

            return english

        else:

            english = OTHER_TENS[number // 10 - 2] + ' ' + FIRST_TEN[number % 10 - 1]

            return english

    else:

        if number % 100 == 0:

            english = FIRST_TEN[number // 100 - 1] + ' ' + HUNDRED

            return english

        else:

            english = FIRST_TEN[number // 100 - 1] + ' ' + HUNDRED + ' ' + checkio(number % 100)

            return english

 


        "sixteen",

        "seventeen",

        "eighteen",

        "nineteen",

    ]

    num2 = [

        "",

        "",

        "twenty ",

        "thirty ",

        "forty ",

        "fifty ",

        "sixty ",

        "seventy ",

        "eighty ",

        "ninety ",

    ]

    num3 = [

        "",

        "one hundred ",

        "two hundred ",

        "three hundred ",

        "four hundred ",

        "five hundred ",

        "six hundred ",

        "seven hundred ",

        "eight hundred ",

        "nine hundred ",

    ]

    num4 = ["", "one thousand"]

 

    if number < 10 or number > 19:

        a = str(number)

        if number < 10:

            a = "000" + a

        elif number < 100:

            a = "00" + a

        elif number < 1000:

            a = "0" + a

        if a[2] == "1":

            spel = num4[int(a[0])] + num3[int(a[1])] + num11[int(a[3])]

        else:

            spel = num4[int(a[0])] + num3[int(a[1])] + num2[int(a[2])] + num1[int(a[3])]

    else:

def checkio(number):

    result = ''

    if number >= 100:

        result += f'{FIRST_TEN[int(number/100)]} hundred '

        number %= 100

    if number >= 20:

        result += f'{OTHER_TENS[int(number/10)-2]} {FIRST_TEN[number % 10]}'

    elif number >= 10:

        result += SECOND_TEN[number % 10]

    else:

        result += FIRST_TEN[number]

    return result.rstrip()

大神解答 NO.3

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):

    d = {f'x{i}': number%10**i//10**(i-1) for i in range(1, 4)}

    res = ''

    if d['x3']:

        res += ' {} {}'.format(FIRST_TEN[d['x3'] - 1], HUNDRED)

    if d['x2'] == 1:

        res += ' {}'.format(SECOND_TEN[d['x1']]) 

  elif d['x2']:

        res += ' {}'.format(OTHER_TENS[d['x2'] - 2])

    if d['x1'] and  not (d['x2'] == 1):

        res += ' {}'.format(FIRST_TEN[d['x1'] - 1])

 

    return res.strip()

外汇返佣 NO.4

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):

    ret =''

    h = number//100

    t = (number - h*100)//10

    f = number - h*100 - t*10

    if h > 0:

        ret += FIRST_TEN[h-1] + ' ' + HUNDRED + ' '

        

    if t == 0 and f > 0:

        ret += FIRST_TEN[f-1] + ' '

    elif t == 1:

        ret += SECOND_TEN[f] + ' '

    elif t>1:

        ret += OTHER_TENS[t-2] + ' '

        if f>0:

            ret += FIRST_TEN[f-1] + ' '

    return ret[:-1]

 

阅读(48) | 评论(0) | 转发(0) |
0

上一篇:Py执行命令和拷贝

下一篇:Py序列—词典

给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册