+ 7
Can I use lambda to evaluate x for user given functions??
5 odpowiedzi
+ 9
yup
use eval to evaluate the given user input
f=eval(input("Enter the function: "))
# input: lambda x:x*x
print(f(8)) #outputs 64
+ 6
print("Thanks Burey")
print("Needed that for something")
+ 5
you mean something like this?
def sqr(x):
return x*x
f=lambda x:sqr(x)
print(f(2))
+ 5
no problem :)
happy to help
+ 4
nope
x=input("Enter the function: ")
y=lambda z: x
print(y(8))
something like that