好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

用50行Python代码制作一个计算器

简介

为了美观,我们把它封装到一个不错的计算器 REPL:

defmain():

calc=Calc()

whileTrue:

try:

s=raw_input('> ')

exceptEOFError:

break

ifs=='':

break

tree=calc_grammar.parse(s)

printcalc.transform(tree)

完整的代码可从这里获取:

https://github.com/erezsh/plyplus/blob/master/examples/calc.py

查看更多关于用50行Python代码制作一个计算器的详细内容...

  阅读:74次