Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Read this: https://realpython.com/python-eval-function/#minimizing-the-security-issues-of-eval
- """
- import math
- def evaluate(user_input):
- functions = {
- "sin": math.sin,
- "cos": math.cos,
- "tan": math.tan,
- "pi": math.pi,
- "log": math.log
- }
- globals = {"__builtins__": {}}
- return eval(user_input, globals, functions)
- evaluate("sin(pi * 2)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement