New course! Every coder should learn Generative AI!
Try a free lesson+ 4
I only saw it now, that output shoud be horizontally. You can use this print statement instead of the one i postet:
print (a, end = ', ')
# output: 0, 1, 1, 2, 3, 5, 8,
+ 3
that’s the revised code:
a, b= 0, 1
while (a<10):
print (a)
a, b= b, a+b
+ 2
hi, this code has some issues to run properly.
1 - indentation in line "while..." has to be removed
2 - " , end= 1,1" does not work and has to be removed print(a) is ok
+ 1
Hi Bhavya, this is a smart piece of code for Fibonacci series.
Correct Program (after indentation correction):
a, b= 0, 1
while (a<10):
print (a)
a, b= b, a+b
this line: a,b = b, a+b
is just swapping the value of a, b with b, a+b every time in the loop. Loop will at 8 number < 10.
Hope, you've understood my point. Let me know in case if you're looking for more details. You can try in debug mode to understand the loops jumping and check step by step changes.
+ 1
This link may help you :
https://www.tutorialgateway.org/JUMP_LINK__&&__python__&&__JUMP_LINK-fibonacci-series-program/
But, the output is in vertical form (code inside link)
0
Where did you find this program?
There are mistakes in it and the indentation is over the place...
0
idk if recursion works in javascript but i wrote a program in java that used recursion to write the fibonacci sequence
- 4
3