推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
1oscar
V2EX  ›  Python

python 高手, 求解表达式,要求结果为整数?

  •  
  •   1oscar · Jul 6, 2015 · 3694 views
    This topic created in 4008 days ago, the information mentioned may be changed or developed.

    #如题

    问题:
    *对如下的列表中元素进行如下计算,要求结果必须为整数*

    ['3', '13', '5', '/', '+']      =>     (3+13/5)  =  6
     ['3', '4', '+', '*', '5']     =>   (3+4)  *  5  = 35
    
    1. 请教高手这道题怎么破?
    Supplement 1  ·  Jul 6, 2015
    已经解决,请不用回复了, 地址:[expression ](https://github.com/1oscar/exercises/tree/master/cal_math_expression)
    8 replies    2015-07-06 15:03:26 +08:00
    Septembers
        1
    Septembers  
       Jul 6, 2015 via Android
    laoyuan
        2
    laoyuan  
       Jul 6, 2015
    第一题是 (13 + 5) / 3
    qianlv
        3
    qianlv  
       Jul 6, 2015
    @Septembers 第二个不是逆波兰表示法吧???
    firefffffffffly
        4
    firefffffffffly  
       Jul 6, 2015
    两个示例都有些奇怪,如果是逆波兰表示法,那就用栈解决。
    cc7756789
        5
    cc7756789  
       Jul 6, 2015
    第一次接触这东西,这样是正确的RPN吗?
    [asaa]()
    hahastudio
        6
    hahastudio  
       Jul 6, 2015
    题目不是很明确

    是输出不要输出小数,还是说要凑出一个表达式,使得结果是整数
    比如第一个样例期望的到底是 int(round(3 + 13 / 5)) = 6,还是 (13 + 5) / 3 = 6
    有多种结果的话,是输出哪个结果?
    比如第二个,怎么组合都会返回整数的,是返回 3 * 4 + 5 = 17 呢,还是 (3 + 4) * 5 = 35 呢
    imn1
        7
    imn1  
       Jul 6, 2015
    我想知道加减乘除没有除法运算,一堆整数怎么变成非整数?
    SmiteChow
        8
    SmiteChow  
       Jul 6, 2015
    数字push stack, 遇到操作符号,pop stack 两次,算出结果后push stack
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5331 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 57ms · UTC 07:22 · PVG 15:22 · LAX 00:22 · JFK 03:22
    ♥ Do have faith in what you're doing.