issue with yield | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

issue with yield

I wrote his code: def count(): i=10.4 while i>0: yield i i-=1 for i in count(): print(i) the output I got was: 10.4 9.4 8.4 7.4 6.4 5.4 4.4 3.4000000000000004 2.4000000000000004 1.4000000000000004 0.40000000000000036 can someone explain why the difference between values changes to something else then 1.0 after a certain point? I tried with different examples, like 8.7 or 14.3 and it's the same. it doesn't happen though if the float ends with 0 or 5, for example 6.5 or 20.0. neither does it happen when I write i+=I, only when it goes from bigger to smaller value.

20th Feb 2020, 7:46 PM
1 Answer
+ 3
Issue is not with yeild. It with floating point values.. It's because of compiler internal operations with float values..
20th Feb 2020, 8:07 PM
Jayakrishna 🇮🇳