九州体育网 - 十年信誉网站

关于作者

Discuss / Python / 日常交作业

日常交作业

Topic source

WHU-Jock

#1 Created at ...

from functools import reduce

def str2num(s): return float(s)

def calc(exp): ss = exp.split('+') ns = map(str2num, ss) return reduce(lambda acc, x: acc + x, ns)

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()


  • 1

Reply

WARNING: You are using an old browser that does not support HTML5. Please choose a modern browser (Chrome / Microsoft Edge / Firefox / Sarafi) to get a good experience.