-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabC.py
50 lines (37 loc) · 1.34 KB
/
labC.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
# Higor Martinez Oliveira
#Exercicio 1
def positivo(numero):
"""Retorna o valor absoluto de um número"""
try:
return abs(float(numero))
except ValueError:
print("'%s' não pode ser convertido em um número" % numero)
return None
#Exercicio 2
def encontraIndices(lista, elemento):
"""Retorna uma lista de índices de um elemento dentro da lista dada"""
listaIndices = []
try:
list.append(listaIndices, list.index(lista, elemento))
while len(listaIndices) < list.count(lista, elemento):
list.append(listaIndices, list.index(lista, elemento, listaIndices[-1]+1))
return listaIndices
except ValueError:
return []
#Exercicio 3
def inversos(ListaTupla):
"""Retorna o inverso dos elementos de uma lista ou tupla dada"""
listaInversos = []
for i in ListaTupla:
try:
list.append(listaInversos, 1/float(i))
except ValueError:
print("Inverso de '%s' não definido" % i)
list.append(listaInversos, "Nan")
except TypeError:
print("Entrada de tipo %s não válida" % type(i))
list.append(listaInversos, "Nan")
except ZeroDivisionError:
print("Divisão por zero")
list.append(listaInversos, "Nan")
return listaInversos