0

I am using Python.

I am trying to pass a tuple as an input variable ('myvar') to a function, which I then solve. The error message I receive is

NameError: name 'myvar' is not defined

Here the (minimal) snippet of the code I tried:

from scipy.optimize import fsolve
vss = ('myvar')

def f_nb(*vss):
    nb= 0.8 - myvar
    return nb

def tryit(xx):
    myvar = xx
    zz= f_nb(myvar)
    return zz

solz = fsolve(tryit, (0.2))

solz
night_owl89
  • 101
  • 2
  • 1
    Where is defined `fsolve` ? – Glauco May 19 '23 at 15:36
  • 1
    What tuples? `('myvar')` is a parenthesized string; `('myvar', )` is a tuple containing a single string. Also, why does `f_nb` take arbitrary positional arguments when you only want one specific named parameter? That said, you can define `myvar, *_ = args` inside the function to unpack the arguments. – chepner May 19 '23 at 15:47
  • I included arbitrary positional arguments for generality. Your proposed solution works. Thank you. – night_owl89 May 19 '23 at 15:52

0 Answers0