DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '.': 0}
def fn(x, y):
if y == 0:
return x * 1 + y
else:
return x * 10 + y
def char2num(s):
return DIGITS[s]
n = 0
while s[n] != ".":
n = n+1
a=1
while n>0:
a = a * 10
n=n-1
return reduce(fn, map(char2num, s))/a
Sign in to make a reply
忧雅Beautiful
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '.': 0}
def fn(x, y):
if y == 0:
return x * 1 + y
else:
return x * 10 + y
def char2num(s):
return DIGITS[s]
n = 0
while s[n] != ".":
n = n+1
a=1
while n>0:
a = a * 10
n=n-1
return reduce(fn, map(char2num, s))/a