#๐ Writing a function that takes a set of variables, and an expression in these variables.
9 messages ยท Page 1 of 1 (latest)
@dawn sigil
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
To be clear, when the function is called, I want to be able to input func as an expression of the symbols in vars
pretty sure you just need to define the symbols before then pass it normally? e.g. ```py
x = sp.Symbol('x')
func = x**2 + 2*x + 1
result = calculate(func, x)
if you want a more complete example doing non-trivial operations: <https://claude.ai/public/artifacts/53697402-7aeb-4037-9815-8486ec2c4792>
for multiple variables I would probably recommend something like ```py
x, y, z = sympy.symbols("x y z")
def calculate(func, **vars):
return func.subs(vars)
calculate(x+y+z, x=x, y=y, z=z)
calculate(x+y+z, x=1, y=2, z=3)
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.