Noob Cube Root Program | Sololearn: Learn to code for FREE!

+1

Noob Cube Root Program

So made this program for the cube root challenge and it calculates the cube root till the precision of 0.0001(as required in the challenge). There is one problem though. It gives some nonsense decimal digits after giving the answer. I don't understand why my loop isn't breaking after the answer has achieved the required precision. I just started coding yesterday so I am a super noob, please keep that in mind while answering. https://code.sololearn.com/cGw5PaRDRHfo/?ref=app

9/21/2019 6:26:39 AM

Swastik Verma

2 Answers

New Answer

+2

Those "nonsense" digits appear because decimals can't be represented exactly in binary. print(0.1+0.2==0.3) # False # But it's clearly True print(0.1+0.2) # 0.30000000000000004 https://stackoverflow.com/questions/1089018/#1089026

+2

Thanks Diego. Atleast I know that my logics were not wrong lol.