Discuss / Python / 作业8

作业8

Topic source

孤o赦免你

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

from functools import reduce

def normalize(name):

    return name[0].upper() + name[1:].lower()

def prod(L):

    return reduce(lambda x, y: x * y, L)

def str2float(string):

    def list2int(x, y):

        return x * 10 + y

    def str2num(s):

        d = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}

        return d[s]

    def dian(str):

        int_ = '0'

        float_ = ''

        fi = True

        for s in str:

            if s == '.':

                fi = False

            else:

                if fi:

                    int_ = int_ + s

                else:

                    float_ = float_ + s

        return int_, float_            

    s1,s2 = dian(string)

    num_float = list(map(str2num, s2))

    return reduce(list2int,map(str2num, s1)) + reduce(list2int,num_float) / pow(10,len(num_float))


  • 1

Reply