Discuss / Python / 第三题

第三题

Topic source

俯仰瞬间

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

有大佬帮忙看一下哪里出错了吗?偏差太大了

    dict = {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6}
    def charToNum(ch):
        return dict[ch]
    def strToInt(x, y):
        if str(y) in s[:dotIndex]:
            return x*10 + y
        else:
            n = s.find(str(y)) - dotIndex
            return x + 0.1*n*y
    dotIndex = s.find('.')
    return reduce(strToInt, map(charToNum, s.replace('.', '')))

欽琼醉

#2 Created at ... [Delete] [Delete and Lock User]
dict = {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6}
    def charToNum(ch):
        return dict[ch]
    def strToInt(x, y):
        if str(y) in s[:dotIndex]:
            return x*10 + y
        else:
            n = s.find(str(y)) - dotIndex
            return x + 0.1**n*y
    dotIndex = s.find('.')
    return reduce(strToInt, map(charToNum, s.replace('.', '')))

  • 1

Reply