I'm using Python 3.7.4. I was wondering about how to keep track of symbols like: +, /, -, * in a string. But I mean with out the ''
and ""
in front and behind of it. I'm creating a calculator as my project. This is what it looks like:
When ever you click on one of the buttons it adds that number to a string like user_text = ''
. So like a blank string. So say you have in 9 + 9
the string when ever you added it together you get 18. But the problem lies with: +, /, -, *. Cause I know how to turn a string into a number and then add them together or any other way. But, how would you keep track of the symbols in the string and add the numbers in the string to each other with the symbol with it. So, with the correct operation.
I've tried to do: if '+' in len(user_text): print("Yes")
but then I realize that it can't iterate a string for int
. Anything with range is out of the question I realized too. I was thinking about having like a back up line, but as a list then append what ever was entered onto the list. Then keep track of it. Like say user_list = []
then you added 4 + 4 onto the list user_list = ['4', '+', '4']
. But then again how would I keep track of the symbols I said, but then add the 2 strings numbers together as an int
to get 8. I just can't think of a way to do something like this. I might be overthinking this but I just can't think of it.
If I can provide anymore information on my issue or anything, let me know. I appreciate the advice and help. Thank you.