0
Why is there no output? I should have n?
6 Answers
+ 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.
+ 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.
+ 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.
+ 1
So what should I do
+ 1
Thank you Lothar but I'm not sure how to do that
+ 1
ok thank you Lothar