Discuss / Python / 第三题

第三题

Topic source

wujinkongxu

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

def str2float(s): dic_1 = {'0':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, '.':'.'} def char2num(s): return dic_1[s] r = list(map(char2num, s)) def iwantint(s): r1 = [] n = 0 while s[n] != '.': r1.append(s[n]) n = n + 1 return r1 r1 = iwantint(r) def fn_1(x, y): return x * 10 +y r11 = reduce(fn_1, r1) def iwantfloat(s): r2 = [] m = len(s) - 1 while s[m] != '.': r2.append(s[m]) m = m - 1 return r2 r2 = iwantfloat(r) def fn_2(x,y): return x / 10 +y r21 = reduce(fn_2, r2) return r11 + r21 / 10


  • 1

Reply