Discuss / Python / 交作业

交作业

Topic source
def normalize(name):
    low = ''
    x = 0
    for i in name:
        if x == 0:
            low = low + i.upper()
            x = x + 1
        else:
            low = low + i.lower()
            x = x + 1
    return low

def prod(L):
    def fn(x, y):
        return x*y
    return reduce(fn, L)

def str2float(s):
    l = s.split('.')
    n = len(l[1])
    digits = {'0':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}
    def str2num(s):
        return digits[s]
    def fn(x, y):
        return x * 10 + y
    n1 = reduce(fn, map(str2num, l[0]))
    n2 = reduce(fn, map(str2num, l[1]))
    return n1 + n2 * pow(10, -n)

青稚町

#2 Created at ... [Delete] [Delete and Lock User]

要是'12345.6'咋办


  • 1

Reply