Nov-13-2022, 05:36 PM
(This post was last modified: Nov-13-2022, 05:37 PM by deanhystad.)
It is a function, sort of, but it doesn't do anything. It doesn't produce a result.
Do not define a function inside a while loop. It is not an error to do so, but it is not where I would expect to find a function definition. Functions are usually defined near the top of a module. fibo() should appear above "while True:" in the file.
Don't use global variables to pass information to a function. Use function arguments.
Your function doesn't return a value. It calculates numbers, but nothing is done, or can be done, with those numbers. I would write this function as a generator, but maybe you should start out with returning the last number in the sequence or a list of the numbers.
Why are you limiting howMany to be > 5?
fibo(0) : None? Empty list?
fibo(1) : 1
fibo(2) : 1 1
fibo(3) : 1 1 2
fibo(4) : 1 1 2 3
Why are you using a while loop to compute the numbers? You know how many times the loop needs to run. Use "for _ in range(howMany):". Let python do the loop counting for you.
Why are there 3 variables, a, b, c? I know you are using c as a temporary swap variable to hold the sum of a+b, but you don't need swap variables in Python. In python you can do this:
Do not define a function inside a while loop. It is not an error to do so, but it is not where I would expect to find a function definition. Functions are usually defined near the top of a module. fibo() should appear above "while True:" in the file.
Don't use global variables to pass information to a function. Use function arguments.
Your function doesn't return a value. It calculates numbers, but nothing is done, or can be done, with those numbers. I would write this function as a generator, but maybe you should start out with returning the last number in the sequence or a list of the numbers.
Why are you limiting howMany to be > 5?
fibo(0) : None? Empty list?
fibo(1) : 1
fibo(2) : 1 1
fibo(3) : 1 1 2
fibo(4) : 1 1 2 3
Why are you using a while loop to compute the numbers? You know how many times the loop needs to run. Use "for _ in range(howMany):". Let python do the loop counting for you.
Why are there 3 variables, a, b, c? I know you are using c as a temporary swap variable to hold the sum of a+b, but you don't need swap variables in Python. In python you can do this:
a, b = b, a+bwhich does the same as:
c = a + b a = b b = c