- 3

What is wrong in logic in this python code snippet? It executes indefinitely! !

The code tries to print fibonoci numbers up to 10

30th Jul 2021, 11:52 AM
Martin Raj Kumar
Martin Raj Kumar - avatar
9 Answers
+ 3
Martin Raj Kumar Whenever you are posting a question after relevant tags Insert option is there + symbol if you click on that you will get 2 options Insert code Insert post Otherwise copy code and paste it here
30th Jul 2021, 12:05 PM
RšŸšŸ‡®šŸ‡³
RšŸšŸ‡®šŸ‡³ - avatar
+ 3
Martin Raj Kumar Before applying condition check it If you take 2<10 or 3<10 the loop will be infinite.
30th Jul 2021, 12:19 PM
RšŸšŸ‡®šŸ‡³
RšŸšŸ‡®šŸ‡³ - avatar
+ 2
Guys I believe that is the code he meant: t1=0 t2=1 c = 2 d =0 while c< 10: d =t1+t2 t1 = t2 t2 = d ++c print (d)
30th Jul 2021, 12:10 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 2
But anyways here is working Fibonacci code: num1, num2 = 0, 1 count = 0 while count < 10: print(num1) sum = num1 + num2 num1 = num2 num2 = sum count += 1
30th Jul 2021, 12:18 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 2
Thanks a lot Alex. ..
30th Jul 2021, 12:20 PM
Martin Raj Kumar
Martin Raj Kumar - avatar
+ 2
C+=1 will make the code work and u checked it.
30th Jul 2021, 1:16 PM
Martin Raj Kumar
Martin Raj Kumar - avatar
+ 1
Martin Raj Kumar Share your code
30th Jul 2021, 11:58 AM
RšŸšŸ‡®šŸ‡³
RšŸšŸ‡®šŸ‡³ - avatar
+ 1
You probably have an error in your code but we can not help you unless you post your code.
30th Jul 2021, 11:59 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
I don't know how to inset my code
30th Jul 2021, 12:01 PM
Martin Raj Kumar
Martin Raj Kumar - avatar