solution of problem 3
Topic sourcecorrection
# map reducefrom functools import reduce
# self-defined int() funcDIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
def char_to_num(s):
return DIGITS[s]
def str_to_int(s):
return reduce(lambda x, y: x * 10 + y, map(char_to_num, s))
# self-defined float() funcdef str_to_float(s):
sl = s.split('.')
sl1 = list(sl[0])
sl2 = list(sl[1])
sl2.reverse()
return reduce(lambda x, y: x * 10 + y, map(char_to_num, sl1)) +\
0.1 * reduce(lambda x, y: x * 0.1 + y, map(char_to_num, sl2))
# map reducefrom functools import reduce
# self-defined int() funcDIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
def char_to_num(s):
return DIGITS[s]
def str_to_int(s):
return reduce(lambda x, y: x * 10 + y, map(char_to_num, s))
# self-defined float() func
def str_to_float(s):
sl = s.split('.')
sl1 = list(sl[0])
sl2 = list(sl[1])
sl2.reverse()
return reduce(lambda x, y: x * 10 + y, map(char_to_num, sl1)) +\
0.1 * reduce(lambda x, y: x * 0.1 + y, map(char_to_num, sl2))
- 1
在路上Ce