Jump to content

Code not calling


Recommended Posts

Hi, is there any reason why this code is not calling?

I am sure I copied it right.

Thanks

-------

def fib2(n): # return Fibonacci series up to n

"""Return a list containing the Fibonacci series up to n."""

result = []

a, b = 0, 1

while a < n:

result.append(a) # see below

a, b = b, a+b

return result

f100 = fib2(100)

f100

------

If I add

print (f100)

I get a print out but I thought this calls the list without the need to print?

Edited by Alan Woodwell
Link to comment

Hi Alan

Where are you running your script?

In the script editor for vectorworks?

or the Python IDE?

If in the script editor, the print function displays only if an error has occured and you inspect the error.

I normally use the vs.Message() or vs.AlrtDialog() calls to query variables in code. both need whatever variable to be of string type.

in this case it would be:

vs.Message(str(f100))

or

vs.AlrtDialog(str(f100))

If in the IDE: I'm running your script from the Python 3.3.3 Shell (Windows 10) and both methods work. ie calling f100 and also print(f100) shows the list of the Fibonacci sequence

Edited by twk
Link to comment

Hi, running it on my iPad.

And using Python 2.7 app

I am still learning how to code and understanding the indenting etc, so I am on a steep learning curve.

I am doing purely Python at present.

Thanks

Edited by Alan Woodwell
Link to comment

ahh ok,

well if its running from a module(.py file, in your case 4.6-04.py), I believe you have to call the 'print' function to display it in the python command prompt.

If you're entering commands directly in the prompt, calling a variable like f100 will display its value on the next line, regardless of calling print or not.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...