-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaula54.py
More file actions
43 lines (37 loc) · 1.07 KB
/
aula54.py
File metadata and controls
43 lines (37 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Faça uma lista de comprar com listas
O usuário deve ter a possibilidade de
inserir, apagar e listar valores da sua lista
Não permita que o programa quebre com
erros de índices inexistentes na lista.
"""
import os
lista = []
while True:
print('Selecione uma opção')
opcao = input('[i]nserir [a]pagar [l]istar: ')
if opcao == 'i':
os.system('clear')
valor = input('Valor: ')
lista.append(valor)
elif opcao == 'a':
indice_str = input(
'Escolha o índice para apagar: '
)
try:
indice = int(indice_str)
del lista[indice]
except ValueError:
print('Por favor digite número int.')
except IndexError:
print('Índice não existe na lista')
except Exception:
print('Erro desconhecido')
elif opcao == 'l':
os.system('clear')
if len(lista) == 0:
print('Nada para listar')
for i, valor in enumerate(lista):
print(i, valor)
else:
print('Por favor, escolha i, a ou l.')