Questão 1
24
10
16
Questão 2
lista_de_tuplas = [('Pedro', 1.74, 81), ('Júlia', 1.65, 67), ('Otávio', 1.81, 83)]
lista = []
for tupla in lista_de_tuplas:
lista.append(tupla[2])
print(lista)
[81, 67, 83]
Questão 3
lista_de_tuplas = []
for i in range(len(lista)):
lista_de_tuplas.append((i, lista[i]))
print(lista_de_tuplas)
[(0, 81), (1, 67), (2, 83)]
Questão 4
aluguel = [('Apartamento', 1700), ('Apartamento', 1400), ('Casa', 2150), ('Apartamento', 1900), ('Casa', 1100)]
lista = [tupla[1] for tupla in aluguel if tupla[0]== 'Apartamento']
print(lista)
[1700, 1400, 1900]
Questão 5
meses = ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez']
despesa = [860, 490, 1010, 780, 900, 630, 590, 770, 620, 560, 840, 360]
dicionario = {meses[i]: despesa[i] for i in range(len(meses))}
print(dicionario)
{'Jan': 860, 'Fev': 490, 'Mar': 1010, 'Abr': 780, 'Mai': 900, 'Jun': 630, 'Jul': 590, 'Ago': 770, 'Set': 620, 'Out': 560, 'Nov': 840, 'Dez': 360}
Questão 6
vendas = [('2023', 4093), ('2021', 4320), ('2021', 5959), ('2022', 8883), ('2023', 9859), ('2022', 5141), ('2022', 7688), ('2022', 9544), ('2023', 4794), ('2021', 7178), ('2022', 3030), ('2021', 7471), ('2022', 4226), ('2022', 8190), ('2021', 9680), ('2022', 5616)]
filtro = [tupla[1] for tupla in vendas if tupla[0] == '2022' and tupla[1] > 6000]
print(filtro)
[8883, 7688, 9544, 8190]
Questão 7
glicemia = [129, 82, 60, 97, 101, 65, 62, 167, 87, 53, 58, 92, 66, 120, 109, 62, 86, 96, 103, 88, 155, 52, 89, 73]
rotulos = [('Hipoglicemia', glicose) if glicose <= 70 else ('Normal', glicose) if glicose < 100 else ('Alterada', glicose) if glicose < 125 else ('Diabetes', glicose) for glicose in glicemia]
print(rotulos)
[('Diabetes', 129), ('Normal', 82), ('Hipoglicemia', 60), ('Normal', 97), ('Alterada', 101), ('Hipoglicemia', 65), ('Hipoglicemia', 62), ('Diabetes', 167), ('Normal', 87), ('Hipoglicemia', 53), ('Hipoglicemia', 58), ('Normal', 92), ('Hipoglicemia', 66), ('Alterada', 120), ('Alterada', 109), ('Hipoglicemia', 62), ('Normal', 86), ('Normal', 96), ('Alterada', 103), ('Normal', 88), ('Diabetes', 155), ('Hipoglicemia', 52), ('Normal', 89), ('Normal', 73)]
Questão 8
id = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
quantidade = [15, 12, 1, 15, 2, 11, 2, 12, 2, 4]
preco = [93.0, 102.0, 18.0, 41.0, 122.0, 14.0, 71.0, 48.0, 14.0, 144.0]
tabela = [('id', 'quantidade', 'preco', 'total')]
tabela += [(id[i], quantidade[i], preco[i], quantidade[i]*preco[i]) for i in range(len(id))]
print(tabela)
[('id', 'quantidade', 'preco', 'total'), (0, 15, 93.0, 1395.0), (1, 12, 102.0, 1224.0), (2, 1, 18.0, 18.0), (3, 15, 41.0, 615.0), (4, 2, 122.0, 244.0), (5, 11, 14.0, 154.0), (6, 2, 71.0, 142.0), (7, 12, 48.0, 576.0), (8, 2, 14.0, 28.0), (9, 4, 144.0, 576.0)]
Questão 9
estados = ['SP', 'ES', 'MG', 'MG', 'SP', 'MG', 'ES', 'ES', 'ES', 'SP', 'SP', 'MG', 'ES', 'SP', 'RJ', 'MG', 'RJ', 'SP', 'MG', 'SP', 'ES', 'SP', 'MG']
estados_unicos = list(set(estados))
lista_de_listas = []
for estado in estados_unicos:
lista = [uf for uf in estados if uf == estado]
lista_de_listas.append(lista)
print(lista_de_listas)
contagem_valores = {estados_unicos[i]: len(lista_de_listas[i]) for i in range(len(estados_unicos))}
print(contagem_valores)
[['SP', 'SP', 'SP', 'SP', 'SP', 'SP', 'SP', 'SP'], ['ES', 'ES', 'ES', 'ES', 'ES', 'ES'], ['RJ', 'RJ'], ['MG', 'MG', 'MG', 'MG', 'MG', 'MG', 'MG']]
{'SP': 8, 'ES': 6, 'RJ': 2, 'MG': 7}
Questão 10
('ES',8), ('SP',9), ('RJ', 13), ('MG', 5), ('RJ', 9), ('SP', 12), ('MG', 10), ('SP', 7), ('ES', 14), ('SP', 10), ('MG', 12)]
estados_unicos = list(set([tupla[0] for tupla in funcionarios]))
lista_de_listas = []
for estado in estados_unicos:
lista = [tupla[1] for tupla in funcionarios if tupla[0] == estado]
lista_de_listas.append(lista)
print(lista_de_listas)
agrupamento_por_estado = {estados_unicos[i]: lista_de_listas[i] for i in range(len(estados_unicos))}
print(agrupamento_por_estado)
soma_por_estado = {estados_unicos[i]: sum(lista_de_listas[i]) for i in range(len(estados_unicos))}
[[16, 10, 7, 11, 9, 12, 7, 10], [8, 9, 7, 12, 8, 14], [13, 9], [9, 6, 4, 8, 5, 10, 12]]
{'SP': [16, 10, 7, 11, 9, 12, 7, 10], 'ES': [8, 9, 7, 12, 8, 14], 'RJ': [13, 9], 'MG': [9, 6, 4, 8, 5, 10, 12]}
{'SP': 82, 'ES': 58, 'RJ': 22, 'MG': 54}