-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
63 lines (45 loc) · 2.36 KB
/
helpers.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
58
59
60
61
62
63
# Função lista_strings_para_string: recebe uma lista de strings e retorna uma string com todas as strings separadas por vírgula
def lista_strings_para_string(lista):
return ", ".join(lista)
# Função printa_matriz: recebe uma matriz e imprime a matriz
def printa_matriz(matriz):
for linha in matriz:
print(linha)
# Função check_1: recebe um número e retorna um x se o número for 1 e um espaço se o número for 0
def check_1(n):
return "X" if n == 1 else " "
# Função lugares_disponiveis: recebe uma matriz e retorna o número de lugares disponíveis na matriz
def lugares_disponiveis(matriz):
return sum(linha.count(0) for linha in matriz)
# Função most_empty: recebe uma lista de salas e retorna a sala com mais lugares disponíveis
# Função que verifica qual sala está mais vazia
def most_empty(matrizes):
quantidade_de_lugares_disponiveis_da_matriz_mais_vazia = 0
for i in matrizes:
for matriz in i:
if matriz != [] and (quantidade_de_lugares_disponiveis_da_matriz_mais_vazia == 0 or quantidade_de_lugares_disponiveis_da_matriz_mais_vazia != 0 and lugares_disponiveis(matriz) > quantidade_de_lugares_disponiveis_da_matriz_mais_vazia):
quantidade_de_lugares_disponiveis_da_matriz_mais_vazia = lugares_disponiveis(
matriz)
return quantidade_de_lugares_disponiveis_da_matriz_mais_vazia
# Função que verifica se a informação foi escrita corretamente
def verificador_input(coisa, lista, condicao, mensagem_erro):
while True:
# Pede um numero para o usuario
numero = int(
input(f"Digite o número {coisa} que você deseja: "))
# Se o numero dado pelo usuario existir dentro da lista de coisas que ele está buscando, ele vai retornar a opção escolhida
if (condicao == 'in' and numero - 1 in range(len(lista))) or (condicao == '<=' and numero <= lista[0] and numero > 0):
return numero
# Se o numero não existir, é printado um aviso
else:
print(mensagem_erro)
'''
# Início teste
lista = ["a", "b", "c"]
print(lista_strings_para_string(lista))
matrizes = [[[0, 0, 1, 1], [0, 0, 0, 0]], [[0, 0, 1, 1], [0, 0, 1, 0]]]
for matriz in matrizes:
if lugares_disponiveis(matriz) == most_empty(matrizes):
print(matriz)
# Fim teste
'''