为了美观,我们把它封装到一个不错的计算器 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代码制作一个计算器的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did86828