Created
June 24, 2014 21:03
-
-
Save maurobaraldi/7870f4f6224e333cb8cb to your computer and use it in GitHub Desktop.
My first parser <3
This file contains hidden or 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
def calculator(expr): | |
l, o, r = expr.strip().split(' ') | |
if o == '+': | |
return eval(l) + eval(r) | |
elif o == '-': | |
return eval(l) - eval(r) | |
elif o == '*': | |
return eval(l) * eval(r) | |
elif o == '/': | |
return eval(l) / eval(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment