Discuss / Python / 作业

作业

Topic source

冰块ZJ

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

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

    def fn(x,y):

        return x * 10 + y

    def char2num(s):

        if s == '.':

            pass

        else:

            return dict[s]

    int_num = reduce(fn,map(char2num,s.replace('.','')))

    for i in s:

        if i == '.':

            index_num = len(s) - s.index(i) -1

    return int_num / (10 ** index_num)


  • 1

Reply