checkio的一些题:Speech Module,Feed Pigeons,Roman numerals,Golden Pyramid,The Most Numbers,Digits Multipl

Speech Module
def checkio(number):
    s = ""
    if number/100 > 0:
        s+=FIRST_TEN[number/100-1]
        s+=" "
        s+=HUNDRED
        number = number%100
        if number > 0:
            s+=" "
    if number >0:
        if number < 20:
            if number < 10:
                s+=FIRST_TEN[number-1]
                return s
            s+=SECOND_TEN[number%10]
        else:
            s+=OTHER_TENS[number/10-2]
            if number%10:
                s+=" "
                s+=FIRST_TEN[number%10-1]
    return s


Feed Pigeons
def checkio(number):
    p = 1
    i = 2
    while number > 0:
        if number - p > 0:
            number = number - p
            p += i
            i += 1
        elif number - p + i - 1 > 0:
            return number
        else:
            return p-i+1


Roman numerals
def checkio(number):
    l = ""
    if number>=1000:
        l+='M'*(number/1000)
        number = number%1000
    if number<1000 and number>=900:
        l+='CM'
        number -=900
    if number<1000 and number>=500:
        l+='D'
        l+='C'*(number/100-5)
        number = number%100
    if number<1000 and number>=400:
        l+="CD"
        number = number%100
    if number<1000 and number>=100:
        l+="C"*(number/100)
        number = number%100
    if number<100 and number>=90:
        l+='XC'
        number -=90
    if number<100 and number>=50:
        l+='L'
        l+='X'*(number/10-5)
        number = number%10
    if number<100 and number>=40:
        l+="XL"
        number = number%10
    if number<100 and number>=10:
        l+="X"*(number/10)
        number = number%10
    if number<10 and number>=9:
        l+='IX'
    if number<9 and number>=5:
        l+='V'
        l+='I'*(number-5)
    if number==4:
        l+="IV"
    if number<4 and number>=1:
        l+="I"*number
    return l


checkio=lambda data: ['','M','MM','MMM'][data//1000]+['','C','CC','CCC','CD','D','DC','DCC','DCCC','CM'][data//100%10]+['','X','XX','XXX','XL','L','LX','LXX','LXXX','XC'][data//10%10]+['','I','II','III','IV','V','VI','VII','VIII','IX'][data%10]


Golden Pyramid
def count_gold(pyramid):
    length = len(pyramid)
    if len(pyramid) == 1:
        return pyramid[0];
    l2=list(pyramid[-1])
    i=2
    while len(l2) != 1 and pyramid[-i+1] != pyramid[0]:
        l1=list(pyramid[-i])
        l3=[]
        for j in range(len(l1)):
            l3.append((l1[j]+max(l2[j],l2[j+1])))
        i+=1
        l2=l3
    return l2[0]


The Most Numbers
def checkio(*args):
    if args:
        return sorted(args)[-1]-sorted(args)[0]
    else:
        return 0


checkio=lambda *args:sorted(args)[-1]-sorted(args)[0] if args else 0


Digits Multiplication
slove=lambda number:int(number[0]) if len(number) == 1 and  number[0]!='0' else 1 if len(number) == 1 and  number[0]=='0'  else int(slove(number[1:])) if number[0]=='0'  else int(number[0])*int(slove(number[1:]))
def checkio(number):
    n=str(number)
    return slove(n)

你可能感兴趣的:(checkio的一些题:Speech Module,Feed Pigeons,Roman numerals,Golden Pyramid,The Most Numbers,Digits Multipl)