Need to find the Fibonacci series up to N terms.
n=int(input("Enter the n terms: "))
f_val=0
fib_list=[f_val:=f_val + i for i in range(n)]
print(fib_list)
While executing the above program, I got the result:
Enter the n terms: 5
[0, 1, 3, 6, 10]
My doubt is: what is the purpose of f_val := f_val + i? I really don't know the purpose of := in Python. Can anyone help me to find the solution?
Correct the code and solution of your doubt is:
f_valis the variable that stores the current value of the Fibonacci-like series.f_val + icalculates the next term by adding the current value off_valwith the loop variablei.f_val := f_val + iassigns the new calculated value tof_valfor the next iteration.