How do I subtract values from a list added by python input

Asked

Viewed 31 times

-4

I’m doing the following:

subtração = list()
    su = int(input('Digite um número inteiro: '))
    subtração.append(su)
    while True:
                resposta = str(input('Deseja continuar? [S/N]')).upper()[0]
                if resposta in 'SN':
                    break
                print ('erro')
            if resposta == 'N':
                break
    sub = 0
    for s in subtração:
      sub -= s
    print(sub)

1 answer

-2

Hello, your question is not clear. Try to describe your question better.

If you want to remove a value from a list lista = [5,8,3] you can use the function .pop() If you want to go through a list and subtract a value from the list it would be

lista = [5,8,3]
num = 3
print(lista)
lista = [x-num for x in lista] 
print (lista)

Don’t forget to study the basics in python. It’s not pythonic to start a list by calling the function list()

Browser other questions tagged

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