Last active
March 4, 2017 02:26
-
-
Save lakinwecker/7437b0ace6d7c0ffcdf4259e39284561 to your computer and use it in GitHub Desktop.
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
from operator import * | |
lookup = { '-': sub, '+': add, '*': mul, '/': truediv, '^': pow} | |
def lwe(e): | |
for ops in ['+-', '/*', '^']: | |
i = max([e.rfind(c) for c in ops]) | |
if i != -1: return lookup[e[i:i+1]](lwe(e[:i]), lwe(e[i+1:])) | |
return float(expr) | |
print(lwe(input("> "))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment