Im writing a code for uni, it's about Reverse Polish Notation. I'm now at a point where I get my answers in the form of '3+4' (so a string), but i want them as a float (so 7.0). (another example is '3+4/2' and 5.0). Is there a 'smart' way to do this?
Asked
Active
Viewed 24 times
-1
-
3Why are you converting it to a string in the first place? Calculate the result when you're parsing the RPN. It's very easy by pushing values onto a stack, then calling a function that corresponds to each operator, and the function pops from the stack. – Barmar May 31 '22 at 20:37