-
Notifications
You must be signed in to change notification settings - Fork 38
ex 5 #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
ex 5 #28
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -36,24 +36,91 @@ def obter_opcao(): | |||||||||||||||||||||||||||
| return codigo_opcao | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def incluir_nova_aluna(): | ||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||
| #TODO - Implentar a função | ||||||||||||||||||||||||||||
| nome = input("Insira o nome:\n") | ||||||||||||||||||||||||||||
| sobrenome = input("Insira o sobrenome:\n") | ||||||||||||||||||||||||||||
| turma = input("Insira a turma:\n") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| notas_input = input("Insira as notas separadas por vírgula:\n") | ||||||||||||||||||||||||||||
| notas = notas_input.split(",") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| presenca_input = input("Insira as presenças separadas por vírgula (1 para presença, 0 para falta)") | ||||||||||||||||||||||||||||
| presenca_lista = presenca_input.split(",") | ||||||||||||||||||||||||||||
| presenca = [True if cada.strip() == "1" else False for cada in presenca_lista] | ||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Temos um operador ternário com um for inline. Cuidado com uso de referências externas no código, neste início de desenvolvimento de lógica de programação, podem atrapalhar o processo. |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| participacao = float(input("Insira a nota de participação")) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if notas and all(0 <= len(nota) <= 10 for nota in notas): | ||||||||||||||||||||||||||||
| global dataset | ||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Não é necessário declarar o dataset, ele já está criado. |
||||||||||||||||||||||||||||
| dataset[(nome, sobrenome)] = { | ||||||||||||||||||||||||||||
| "Turma": turma, | ||||||||||||||||||||||||||||
| "Notas": notas, | ||||||||||||||||||||||||||||
| "Presença": presenca, | ||||||||||||||||||||||||||||
| "Participação": participacao | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| print("Aluna adicionada com sucesso!") | ||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||
| print("Verifique as notas.") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def consultar_lista_alunas(): | ||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||
| #TODO - Implentar a função | ||||||||||||||||||||||||||||
| if not dataset: | ||||||||||||||||||||||||||||
| print("Não há alunas cadastradas.") | ||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||
| for nome, sobrenome in dataset.keys(): | ||||||||||||||||||||||||||||
| print(f"{nome} {sobrenome}") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def consultar_faltas_aluna(): | ||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||
| #TODO - Implentar a função | ||||||||||||||||||||||||||||
| nome_completo = input("Nome completo da aluna: ") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| aluna_encontrada = False | ||||||||||||||||||||||||||||
| for key in dataset.keys(): | ||||||||||||||||||||||||||||
| if f"{key[0]} {key[1]}" == nome_completo: | ||||||||||||||||||||||||||||
| faltas = dataset[key]["Presença"].count(False) | ||||||||||||||||||||||||||||
| print(f"A aluna {nome_completo} possui {faltas} faltas.") | ||||||||||||||||||||||||||||
| aluna_encontrada = True | ||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||
|
Comment on lines
+75
to
+81
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Temos uma complexidade desnecessária no código. O acesso aos dados de uma aluna é feita pela chave, então podemos só acessar os valores. Pensar em códigos mais simples é algo importante na programação. Sugestão:
Suggested change
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if not aluna_encontrada: | ||||||||||||||||||||||||||||
| print(f"A aluna {nome_completo} não foi encontrada.") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def consultar_notas_aluna(): | ||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||
| #TODO - Implentar a função | ||||||||||||||||||||||||||||
| nome_completo = input("Nome completo da aluna: ") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| aluna_encontrada = False | ||||||||||||||||||||||||||||
| for key in dataset.keys(): | ||||||||||||||||||||||||||||
| if f"{key[0]} {key[1]}" == nome_completo: | ||||||||||||||||||||||||||||
| notas = dataset[key]["Notas"] | ||||||||||||||||||||||||||||
| print(f"As notas de {nome_completo} são: {notas}") | ||||||||||||||||||||||||||||
| aluna_encontrada = True | ||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||
|
Comment on lines
+91
to
+96
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assim como a função de faltas, aqui tem uma complexidade desnecessária no código. |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if not aluna_encontrada: | ||||||||||||||||||||||||||||
| print(f"A aluna {nome_completo} não foi encontrada.") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def consultar_status_aprovacao(): | ||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||
| #TODO - Implentar a função | ||||||||||||||||||||||||||||
| nome_completo = input("Nome completo da aluna: ") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| aluna_encontrada = False | ||||||||||||||||||||||||||||
| for key in dataset.keys(): | ||||||||||||||||||||||||||||
| if f"{key[0]} {key[1]}" == nome_completo: | ||||||||||||||||||||||||||||
| notas = dataset[key]["Notas"] | ||||||||||||||||||||||||||||
| presenca = dataset[key]["Presença"] | ||||||||||||||||||||||||||||
| participacao = dataset[key]["Participação"] | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| media = sum(notas) / len(notas) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if media >= 6 and (presenca.count(True) / len(presenca)) >= 0.8 and participacao > 6: | ||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Como boa prática, todo cálculo que precisamos fazer, é recomendado fazer antes de colocar no comparador. Podemos criar uma variável de percentual_presenca, calcular e comparar aqui. |
||||||||||||||||||||||||||||
| status = "Aprovada" | ||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||
| status = "Reprovada" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| print(f"Status de {nome_completo}: {status} | Média: {media:.2f}") | ||||||||||||||||||||||||||||
| aluna_encontrada = True | ||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if not aluna_encontrada: | ||||||||||||||||||||||||||||
| print(f"A aluna {nome_completo} não foi encontrada.") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| main() | ||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ao utilizar split, inserimos os valores em uma lista de strings. Precisamos ficar atentas nas funções prontas que usamos. Isso gera erros na hora de somar as notas na função de consultar_status_aprovacao