AlanW Posted June 14, 2016 Share Posted June 14, 2016 (edited) 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 June 14, 2016 by Alan Woodwell Quote Link to comment
twk Posted June 14, 2016 Share Posted June 14, 2016 (edited) 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 June 14, 2016 by twk Quote Link to comment
AlanW Posted June 14, 2016 Author Share Posted June 14, 2016 (edited) 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 June 14, 2016 by Alan Woodwell Quote Link to comment
twk Posted June 14, 2016 Share Posted June 14, 2016 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. Quote Link to comment
AlanW Posted June 14, 2016 Author Share Posted June 14, 2016 Thanks, I got that now but am sure I will be asking a lot of Noob questions soon. Quote Link to comment
Recommended Posts
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.