看了大神的,觉得我的太麻烦,汗,但是坚持打卡
char2float= {'0': 0.0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9} def strtfloat(s): s = map(lambda ch: char2float[ch], s) return reduce(lambda x, y: x * 10 + y, s) def strtx(s): s = map(lambda ch: char2float[ch], s) return reduce(lambda x, y: x / 10 + y, s) def str2float(s): s = str(s) s = s.split('.') s1 = strtfloat(s[0]) tmp = s[1][::-1] s2 = strtx(tmp) return s1 + s2 / 10 s = input("string") a = str2float(s) print(a)``
Sign in to make a reply
Irrelevant-number
看了大神的,觉得我的太麻烦,汗,但是坚持打卡