y = input( ‘Введите функцию’ )
x = input( ‘Введите аргумент (x)’ )
answer = y(x)
y = input( 'Введите функцию: ' )
x = int( input( 'Введите аргумент (x): ' ) )
def function(x):
return eval(y)
print( 'Ответ: ' + function(x))
import sys
this_module = sys.modules[__name__]
def square(x):
return x * x
print(getattr(this_module, 'square')(10))
Foo
Process finished with exit code 0
def square(x):
return x * x
functions = {
'square': square
}
print(functions['square'](10))
100
Process finished with exit code 0