Merged interactive code to the main program for an upcoming demo, will be reverted back after all that.

This commit is contained in:
2020-04-20 02:13:01 -05:00
parent 7507db75b3
commit 53f3058194
4 changed files with 120 additions and 18 deletions
+7 -5
View File
@@ -1,6 +1,8 @@
import ptoken as token
import copy
debug = False
def calculate_results(tokens):
new_list = copy.deepcopy(tokens)
new_list.reverse()
@@ -244,19 +246,19 @@ def operate(n1, n2, tokenType):
n2 = float(n2)
if tokenType == token.TokenType.add:
#print("Adding %d and %d to get %d." %(n1, n2, n1 + n2))
if debug: print("Adding %d and %d to get %d." %(n1, n2, n1 + n2))
return n1 + n2
elif tokenType == token.TokenType.subtract:
#print("Subtracting %d and %d to get %d." %(n1, n2, n1 - n2))
if debug: print("Subtracting %d and %d to get %d." %(n1, n2, n1 - n2))
return n1 - n2
elif tokenType == token.TokenType.multiply:
#print("Multiplying %d and %d to get %d" %(n1, n2, n1 * n2))
if debug: print("Multiplying %d and %d to get %d" %(n1, n2, n1 * n2))
return n1 * n2
elif tokenType == token.TokenType.divide:
#print("Dividing %d and %d to get %d" %(n1, n2, n1 / n2))
if debug: print("Dividing %d and %d to get %d" %(n1, n2, n1 / n2))
return n1 / n2
elif tokenType == token.TokenType.power:
#print("Raising %d to the power of %d to get %d" %(n1, n2, n1**n2))
if debug: print("Raising %d to the power of %d to get %d" %(n1, n2, n1**n2))
return n1 ** n2
else:
raise TypeError("Invalid operator value " + str(tokenType) + ".", tokenType)