Discuss / Python / 交作业

交作业

Topic source

第一题:

def normalize(name):

    string = ''

    for i,value in enumerate(name):

        if i == 0:

            string = string + value.upper()

        else:

            string = string + value.lower()

    return string

第二题:

def prod(L):

    return reduce(cal,L)

def cal(x,y):

    return x * y

第三题:

def str2float(s):

    return reduce(a,map(b,s))

def a(x,y):

    if y < 1:

        return x + y * 10

    return x * 10 + y

def b(s):

    dicts = {"1":1,"2":2,"3":3,".":0,"4":0.04,"5":0.005,"6":0.0006}

    return dicts[s]


  • 1

Reply