RosettaCodeData/Task/Runtime-evaluation-In-an-environment/Python/runtime-evaluation-in-an-environment-2.py

10 lines
248 B
Python
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
>>> def eval_with_args(code, **kwordargs):
return eval(code, kwordargs)
>>> code = '2 ** x'
>>> eval_with_args(code, x=5) - eval_with_args(code, x=3)
24
>>> code = '3 * x + y'
>>> eval_with_args(code, x=5, y=2) - eval_with_args(code, x=3, y=1)
7