5

I'm trying to set a default value for an argument in a function I've defined. I also want another argument to have a default value dependent on the other argument. In my example, I'm trying to plot the quantum mechanical wavefunction for Hydrogen, but you don't need to know the physics to help me.

def plot_psi(n,l,start=(0.001*bohr),stop=(20*bohr),step=(0.005*bohr)):

where n is the principle quantum number, l is the angular momentum and start,stop,step will be the array I calculate over. But what I need is that the default value of stop actually depends on n, as n will effect the size of the wavefunction.

def plot_psi(n,l,start=(0.001*bohr),stop=((30*n-10)*bohr),step=(0.005*bohr)):

would be what I was going for, but n isn't yet defined because the line isn't complete. Any solutions? Or ideas for another way to arrange it? Thanks

1 Answer 1

3

Use None as the default value, and calculate the values inside the function, like this

def plot_psi(n, l, start=(0.001*bohr),stop=None,step=(0.005*bohr)):
    if stop is None:
        stop = ((30*n-10)*bohr)
Sign up to request clarification or add additional context in comments.

1 Comment

Shouldn't it be if stop is None ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.