1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How do I create a space after every 4 bits in python in a binary conversion program

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    import collections
    from collections import Counter
    d = int(input('Pick a number to convert to Binary: '))

    def convert(n, Counter = 0):
    Counter = 0
    if n > 1:
    convert(n//2)
    print(n % 2, end = '')


    print("Your number in Binary is")
    convert(d)


    I have no idea how to create a space every 4 bits or every 4 numbers in the output. I tried using a counter a for loop and pretty much everything I can think of. I just want to know how I would be able to do this. Any help would be appreciated, i'm just lost.

    Continue reading...

Compartilhe esta Página