Created
February 13, 2017 14:35
-
-
Save MagicHen25/75ec51a91ee27e9f671072ca8a4fe79c to your computer and use it in GitHub Desktop.
calc v0.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2) ) | |
''' | |
import re | |
calcStr = "1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2) )" | |
calcStr = re.sub("\ ","",calcStr) # 清除输入中的空格 | |
sepStr = "" | |
def strExecute(inStr): #查找字符串中的最高优先级算式,并返回字符串 | |
# print(inStr) | |
outStr = "" | |
outStr = re.search("\([\(\)\+\-\*/\d]+",inStr) | |
if ((outStr is not None) and ("(" in inStr)): | |
outStr = strExecute(outStr.group(0)[1:]) | |
# return outStr | |
return re.search("[^\(\)]*",outStr).group(0) | |
else: | |
# return inStr | |
return re.search("[^\(\)]*",inStr).group(0) | |
sepStr = strExecute(calcStr) | |
print("[Final]:",sepStr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment