Discuss / Python / 作业

作业

Topic source

第一题

#def transfer(c):
    return c[0].upper() + c[1:]

第三题

def str2float(s):
    def fn1(x,y):
        return x*10+y
    def fn2(x,y):
        return 0.1*y + 0.01*x if x > 1 else 0.1*y + 0.1*x
    def char2Num(key):
        return {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}[key]
    l1,l2 = s.split('.')
    l1 = map(char2Num, l1)
    l2 = map(char2Num, l2)
    l3 = []
    for i in l2:
        l3.insert(0, i)
    return reduce(fn1, l1) + reduce(fn2,l3)

看了大家写的发现我真的好多内置函数不知道啊。。

第一题要求其他字母返回小写:return c[0].upper() + c[1:].lower()

天佑龙影

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

第三题fn2处是亮点,,,不知道大神怎么想出来的。。。


  • 1

Reply