+ 1

Could you explain me how to calculated pls ( for loop )

a=1;b=1 for i in range(9): a,b=b,a+b print(b/a) results 2.0 1.5 1.6666666666666667 1.6 1.625 1.6153846153846154 1.619047619047619 1.6176470588235294 1.6181818181818182 I would like to know how to calculated

2nd Sep 2020, 11:04 AM
Paknonkit Kalayapichet
Paknonkit Kalayapichet - avatar
3 Antworten
+ 4
when the loop runs first a=1 and b=2 2/1=2.0 When loop runs second time a=2 and b=3 3/2=1.5 Third time a=3 and b=2+3=5 5/3 =1.6666 And so on
2nd Sep 2020, 11:35 AM
Abhay
Abhay - avatar
+ 6
May be you can tell us what you want to achieve? Please make samples and give us input values, and how your output should be. Thanks!
2nd Sep 2020, 11:25 AM
Lothar
Lothar - avatar
+ 2
okay thank you for the answers ! at first when I saw the question I thought that should be like (a),(b=b),(a+b) so that made me confuse, it should be like this (a,b)=(b,a+b)
2nd Sep 2020, 1:34 PM
Paknonkit Kalayapichet
Paknonkit Kalayapichet - avatar