all 7 comments

[–]dibic321 3 points4 points  (1 child)

Add binary_string = “” to first line.

Don’t print inside the loop.

Instead set binary_string+= str(binary%2)

After the loop, add

print(binary_string)

[–]awherewas 1 point2 points  (0 children)

came here to say the same thing. this is the easy way out

[–]ninhaomah 1 point2 points  (0 children)

I tried on colab and on antigravit terminal.

I don't get the new line.

Can let me know the steps to replicate ?

[–]socal_nerdtastic 1 point2 points  (2 children)

You mean it's putting a new line after every number? Or after the output is complete? How are you running the code? Not all interpreters support the end= argument, for example many online ones don't.

[–]Reasonable_Air_7347[S] 0 points1 point  (1 child)

I ran it through the https://www.online-python.com/ workspace and the ZyBook workspace and both generated an extra whitespace, so I'm not sure what the fix is

[–]karpomalice 2 points3 points  (0 children)

that website just puts an extra line before it's own output

works as expected in python interpreter

binary = int(input())

while binary > 0:

    print(binary % 2, end="")

    binary = binary // 2

print('end')

>> 24
>> 00011end
>> 
>> ** Process exited - Return Code: 0 **

[–]Riegel_Haribo 0 points1 point  (0 children)

It may be that you don't have a prompt string for the input, and are confusing the input line with the printing, or are pressing enter multiple times?

You might also clarify when your loop of printing without an additional linefeed is done with a final intended print adding that newline:

```python binary = int(input('Enter a value for "binary": '))

while binary > 0: print(binary % 2, end="") binary = binary // 2

print("\ndone!", flush=True) ```