Discuss / Python / 第三题

第三题

Topic source

莫名登录

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

from functools import reduce

s = '789.632541' def str2float(s): str = s.split('.') str1 = str[0] str2 = str[1] return reduce(fn,map(char2num,str1))+reduce(fn,map(char2num,str2))*pow(10,-len(str2))

def char2num(s): return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s]

def fn(x, y): return x * 10 + y

print(str2float(s)) print(type(str2float(s)))


  • 1

Reply