# -*- coding: utf-8 -*- def normalize(name): name = name[0].upper() + name[1:].lower() return name # 测试: L1 = ['adam', 'LISA', 'barT'] L2 = list(map(normalize, L1)) print(L2) def prod(L): result = reduce(lambda x, y: x * y, L) return result print('3 * 5 * 7 * 9 =', prod([3, 5, 7, 9])) if prod([3, 5, 7, 9]) == 945: print('测试成功!') else: print('测试失败!') def str2float(s): s1 = s.split(".")[0] s2 = s.split(".")[1] result1 = reduce(lambda x, y: x * 10 + y, map(char2num, s1)) result2 = reduce(lambda x, y: x * 10 + y, map(char2num, s2)) / 10 ** len(s2) result = result1 + result2 return result print('str2float(\'123.456\') =', str2float('123.456')) if abs(str2float('123.456') - 123.456) < 0.00001: print('测试成功!') else: print('测试失败!')
Sign in to make a reply
萌萌小喵姐