from functools import reduce def str2float(s): s = s.split('.') a = s[0] b = s[1] if a[0] == '-': a = a[1:] front = reduce(lambda x,y:y+x*10,map(int,a)) a = 0 if 'e' in b: print('a') for i in b: a += 1 if i == 'e': c = b[a+1:] middle = reduce(lambda x,y:y+x*10,map(int,c)) b = b[:a-1] buttom = reduce(lambda x,y:y+x*10,map(int,b)) result = (front + buttom / 10 ** (len(b))) / 10 ** middle result = -result print(result) return result else: print('b') buttom = reduce(lambda x, y: y + x * 10, map(int, b)) result = front + buttom / 10 ** (len(b)) result = -result print(result) return result else : front = reduce(lambda x, y: y + x * 10, map(int, a)) a = 0 if 'e' in b: print('c') for i in b: a += 1 if i == 'e': c = b[a+1:] middle = reduce(lambda x,y:y+x*10,map(int,c)) b = b[:a-1] buttom = reduce(lambda x,y:y+x*10,map(int,b)) result = (front + buttom / 10 ** (len(b))) / 10 ** middle print(result) return result else: print('d') buttom = reduce(lambda x, y: y + x * 10, map(int, b)) result = front + buttom / 10 ** (len(b)) print(result) return result
标签:10,map,python,float,reduce,int,result,str,print From: https://www.cnblogs.com/gooutlook/p/17173614.html