Display only after typing negative number

Asked

Viewed 28 times

-1

How can I display the conversion results only after the negative number is typed? Currently, it reads and already displays. I wish he could read and only after typing a negative number, he would display the results

def converte(numBinario, base):
    numBinario = str(numBinario)
    numDecimal = (int(numBinario, 2))
    if numDecimal != 0:
        numConvertido = ""
        while numDecimal > 0:
            resto = numDecimal % base
            numConvertido = str(resto) + numConvertido
            numDecimal = numDecimal // base
    else:
        numConvertido = "0"
    return numConvertido


n = int(input())
while n != -1:
    for bases in range(3, 10 + 1):
        convertido = converte(n, bases)
    print()
    n = int(input())
    print(convertido, end=" ")
  • If I understood you will have to save in a list and then print the list. Anyway it seems to have other errors in the code.

  • The way the code is currently running and displaying values, only that it reads and displays, I wish it could read and only after I type the -1 it displays, and I don’t know how to implement this list

1 answer

0

I would replace your while by a while True, and inside it would put an if.

n = int(input())
while true:
if n<0
    for bases in range(3, 10 + 1):
        convertido = converte(n, bases)
    print()
    n = int(input())
    print(convertido, end=" ")
else
    pass

Browser other questions tagged

You are not signed in. Login or sign up in order to post.