Note that there are some explanatory texts on larger screens.

plurals
  1. POPython fills string with unnessecary characters
    text
    copied!<p>In this Python code, I have the following problem. When the result is displayed, I get a bunch of zeros in the result (see below) - otherwise, the result is correct (the ending numbers of the string). Can anyone spot the error?</p> <pre><code>def menu(): binNumber = '' decNumber = float(input("Enter a positive number: ")) decNumber, binNumber = decimalToBinary(decNumber, binNumber) printResult(binNumber) def decimalToBinary(dec, bin): while dec != 0: remain = dec % 2 dec = dec / 2 if remain &gt; 0.5: bin += '1' else: bin += '0' return dec, bin def printResult(binNumber): print("The binary notation is:", binNumber[::-1]) # the last part is to reverse the string menu() </code></pre> <p>This is the result if I type "2"</p> <blockquote> <p>The binary notation is: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload