0

I am making a calculator GUI, and I need to calculate the answers. All the solutions use three variables (num1, num2, operation). But I would prefer a way to solve other problems such as 1+1+1 with other methods do not do. I also store the problem as a string e.g problem = "1+1+1".

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
error 1044
  • 111
  • 1
  • 6
  • Please share a [mre] of your current code and expand on exactly what you're trying to ask. The [ask] page might help. – Random Davis Jan 06 '22 at 19:28
  • If I were you, I'd record every new operation in a array which contains all operations with tuples of (value, operator). Afterwards you can select those tuples with multiplications/divisions to be executed before sum/subtraction – Kypps Jan 06 '22 at 19:32
  • 1
    print(eval("1+1+1")) will output 3 as an int – Marc Jan 06 '22 at 19:35
  • You can evaluate an expression using the built in `eval` function. But be cautious by only allowing a string of numbers and operators that get passed into it. For example `eval("1+1+1")` will return an integer, 3. – Gabe Morris Jan 06 '22 at 19:36

0 Answers0