Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 4
Conversion from binary to decimal
Hey everyone, Iām a bit confused. I was given a task to write a code which would convert binary into decimal (binary fractions as well). The code itself seems running okay, but when I copy it to a compiler on a website, it runs 3 tests correctly and says āruntime errorā on the 4 test. I suppose my code is not very efficient and elegant, but for all my tests it was still working without any mistakes within a second. Please share your thoughts about what could be the alternative solution. https://code.sololearn.com/crj6bAc7FpA3/?ref=app
2 Respostas
+ 2
ļæ¼
codescracker.com
InĀ Python, you can simply use the bin() function toĀ convertĀ from aĀ decimalvalue to its correspondingĀ binaryvalue. And similarly, the int() function toĀ convertĀ aĀ binaryĀ to itsĀ decimalvalue. The int() function takes as second argument the base of the number to be converted, which is 2 incase ofĀ binaryĀ numbers.
+ 1
Mradul Uttam yeah, but the int() function is not working for fractions, or is it?