Merged interactive code to the main program for an upcoming demo, will be reverted back after all that.
This commit is contained in:
+7
-5
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user