from functools import reduce def str2float(s): return float(s) def calc(exp): ss = exp.split('+') return reduce(lambda acc, x: acc + x, map(str2float, ss)) def main(): r = calc('100 + 200 + 345') print('100 + 200 + 345 =', r) r= calc('99 + 88 + 7.6') print('99 + 88 + 7.6 =', r) main()
Sign in to make a reply
艾米与艾米