-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlista_add.py
57 lines (40 loc) · 1.45 KB
/
lista_add.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
lista = []
while True:
acao = input('Selecione a opção:\n[i]nserir [a]pagar [l]istar (ou "sair"): ').lower()
if acao == 'sair':
break
if acao == 'clear':
os.system('clear')
if acao == 'i':
os.system('clear')
print('Lista:')
for indice, item in enumerate(lista):
print(indice, item)
lista.append(input('Digite o ítem para acrescentar: '))
elif acao == 'a':
os.system('clear')
print('Lista:')
if len(lista) == 0:
print('Lista está vazia.')
for indice, item in enumerate(lista):
print(indice, item)
try:
lista.remove(lista[int(input('Digite o ítem para apagar: '))])
except ValueError:
print('Digite apenas numeros inteiros.')
except IndexError:
print('Digite apenas índices presentes na lista.')
# except: -> The Zen of Python: evite 'except(s) Exception(s)'
# print('Vocẽ digitou algo que não é nem inteiro nem esta na lista.')
elif acao == 'l':
os.system('clear')
print('Lista:')
if len(lista) == 0:
print('Lista está vazia.')
for indice, item in enumerate(lista):
print(indice, item)
else:
print("Por favor, digite: 'i', 'a' ou 'l'.")
print()
print('Você saiu do programa.')