- 3
What is wrong in logic in this python code snippet? It executes indefinitely! !
The code tries to print fibonoci numbers up to 10
9 Antworten
+ 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
+ 3
Martin Raj Kumar Before applying condition check it
If you take 2<10 or 3<10 the loop will be infinite.
+ 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)
+ 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
+ 2
Thanks a lot Alex. ..
+ 2
C+=1 will make the code work and u checked it.
+ 1
Martin Raj Kumar Share your code
+ 1
You probably have an error in your code but we can not help you unless you post your code.
+ 1
I don't know how to inset my code