0
How to put a statement that the position in the list is empty and that it is not possible to change or delete the value
import sys
lista = []
resposta = ''
continua = ''
while resposta != 'S':
print('#### MENU ####')
print('[L]istar')
print('[I]nserir')
print('[A]lterar')
print('[D]eletar')
print('[S]air')
resposta = str(input('selecione uma das opcoes: '))
if resposta == 'I':
numero = int(input('digite o numero: '))
lista.append(numero)
print('Valor adicionado com sucesso: ', lista)
continua = str(input('deseja adicionar outro numero? '))
while continua != 'nao':
numero = int(input('digite o numero: '))
lista.append(numero)
print('Valor adicionado com sucesso: ', lista)
continua = str(input('deseja adicionar outro numero? '))
if resposta == 'A':
posicao = int(input('digite a posicao: '))
print(lista[posicao])
lista[posicao] = int(input('digite o novo numero: '))
print(lista)
continua = str(input('deseja modificar outro numero? '))
while continua != 'nao':
posicao = int(input('digite a posicao: '))
print(lista[posicao])
lista[posicao] = int(input('digite o novo numero: '))
continua = str(input('deseja modificar outro numero? '))
if resposta == 'L':
print('valores da lista: ', lista)
if resposta == 'D':
print('digite a posicao do numero que deseja excluir: ')
posicao = int(input('digite a posicao: '))
lista.remove(lista[posicao])
print('valor', posicao, 'deletado com sucesso!')
print(lista)
continua = str(input('deseja deletar outro numero? '))
while continua != 'nao':
print('digite a posicao do numero que deseja excluir: ')
posicao = int(input('digite a posicao: '))
lista.remove(lista[posicao])
print('valor', posicao, 'deletado com sucesso!')
print(lista)
continua = str(input('deseja deletar outro numero? '))
if resposta == 'S':
print("Saindo")
print('PROGRAMA ENCERRADO!!!!')
print(lista)
sys.exit(1)
Could describe better what you want to do and what the difficulty was?
– Woss
Place a warning in the program that the position is not in the list range
– Homero
Yes, basically you’ve already said that in the question, but I say to detail by telling you what the list is, when the program should happen, what it does, what it should do, etc.
– Woss
the list that will be manipulated in the program, is the same
– Homero
Hello Homero, your code is very confusing, instead of using if as the C++ switch, use OO and modularize the code. I could not understand your doubt too well
– Phill
If option "I" is chosen and the person enters 1,2,3, the list will have the positions 0,1,2. So if the person wants to change a value in the list he will select the option "A" and then choose the position he wants between 0.1 and 2, but if he type 3 or qlqr another position outside of what actually exists in the list, a message must be displayed "option is invalid"because the position is empty. And the same goes for deleting an item.
– Homero