Calculator in python

后端 未结 7 937
别那么骄傲
别那么骄傲 2021-01-27 01:45

I am trying to make calculator that can solve expressions with basic 4 operators, like 1+2*3-4/5, however it does not work and I do not know what is wrong. Please check my code.

7条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-27 02:41

    Your dispatching is incorrect. The way you defined your function it will always try to split by '*', which basically calls the ret function recursively with the same arguments...

    You'll have to check first whether an "operator" is present in your argument string at all.

    Think again!

提交回复
热议问题