0

Why is there no output? I should have n?

https://code.sololearn.com/cH8T77JbJ8nq/?ref=app

30th Jan 2020, 11:44 AM
Alexis Durand
Alexis Durand - avatar
6 odpowiedzi
+ 6
# [Edited]: "round()" is not correct, i was in hurry when i wrote the code. # use the new line instead! #Alexis, here is your code modified to run: def limite(): u=0 n=0 while u!=1.999999: n=n+1 #u= round((3*u+2)/(u+2),6) u = float(f'{(3*u+2)/(u+2):.6f}') print(u) # only for test return n print(limite()) #I put in the function call in last line, and the limitation to 6 decimal places.
30th Jan 2020, 3:52 PM
Lothar
Lothar - avatar
+ 4
An other issue in your code is the while condition: while u!=1.999999: After a few iteration var u reaches a value close to 1.999999. But due to insccuracy of float data type it only reaches 1.9999...98. so from then the code does run in sn infinite loop. You should limit the number of decimal places frum var u to the length of places in 1.999999.
30th Jan 2020, 12:15 PM
Lothar
Lothar - avatar
+ 3
Alexis, here is your code modified to run: def limite(): u=0 n=0 while u!=1.999999: n=n+1 u= round((3*u+2)/(u+2),6) print(u) # only for test return n print(limite()) I put in the function call in last line, and the limitation to 6 decimal places.
30th Jan 2020, 12:45 PM
Lothar
Lothar - avatar
+ 1
So what should I do
30th Jan 2020, 11:49 AM
Alexis Durand
Alexis Durand - avatar
+ 1
Thank you Lothar but I'm not sure how to do that
30th Jan 2020, 12:17 PM
Alexis Durand
Alexis Durand - avatar
+ 1
ok thank you Lothar
30th Jan 2020, 12:46 PM
Alexis Durand
Alexis Durand - avatar