Discuss / Python / 交作业

交作业

Topic source

Tonight_dou

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

第一题

def normalize(name):
    return name.capitalize();

第二题

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

第三题


from functools import reduce
def str2float(str):
    a = str.index('.')
    L1 = [x for x in str[:a]]
    L2 = [x for x in str[a+1:]]
    L2 = L2[::-1]
    L1 = map(int, L1)
    L2 = map(int, L2)
    def f1(x, y):
        return x * 10 + y;
    b = reduce(f1, L1)
    def f2(x, y):
        return x / 10 + y;
    c = reduce(f2, L2)
    d = b + c/10
    print(d)

str2float(input('请输入一个浮点数...'))

  • 1

Reply