Calculator in python

后端 未结 7 846
别那么骄傲
别那么骄傲 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:42

    I have an alternative to your code. The user can enter stuff like: 8*6/4-3+3 and this will still work. Very compact and if you want a command to exit out of the:

    while True:
    

    Just add:

    if(y == "end" or y == "End"):
        break
    

    And it will exit out of the "while True:"

    Code (Python v3.3.0):

    while True:
        x = "x="
        y = input(" >> ")
        x += y
        exec(x)
        print(x)
    
    0 讨论(0)
提交回复
热议问题