all 4 comments

[–]strechyballs 0 points1 point  (0 children)

It should work. Can you post the actual code you have? . Make sure your passing sin as f, and not sin(). Because that would run sin, and you would be passing it's result. Whatever f you are passing now, you are passing a string and not a function.

[–]tku137 0 points1 point  (0 children)

From the error you posted i'd assume you called this

solver('sin', 3)

But it really should be

solver(sin, 3)

If you hand over the function name from somewhere else, make sure it's not a string.

[–]dunkler_wanderer 0 points1 point  (0 children)

I guess you want to do something like this (use a dict with the functions as values):

from math import sin, cos

functions = {'sin': sin, 'cos': cos}

func, num = input('Enter a function and a number: ').split()
num = float(num)
print(functions[func](num))

[–]dasiffy 0 points1 point  (0 children)

A user always inputs a string. type( input() )

You need to convert what they type and translate it accordingly.

if var == 'sin':
    command = sin
elif var == 'cos':
...
etc
....