-1
class Aluno:
nome = ""
ra = int
nota_ac = []
nota_prova = float
faltas = int
media = float
aprovado = bool
def __init__(self, arquivo):
self.arquivo = open(arquivo, 'r')
linha = self.arquivo.read()
palavra = linha.split("\n")
self.nome = palavra[0]
self.ra = palavra[1]
for x in palavra[2:6+1:1]:
self.nota_ac.append(float(x))
self.nota_prova = float(palavra[7])
self.faltas = int(palavra[8])
self.media = 0.0
self.aprovado = False
self.arquivo.close
def calcular_aprovacao(self):
self.media = ((sum(self.nota_ac)/5) + (self.nota_prova))/2
if self.media >= 6.0 and int(self.faltas) <= 20:
self.aprovado = True
return self.aprovado
else:
self.aprovado = False
return self.aprovado
def mostrar_nota(self):
self.media = ((sum(self.nota_ac)/5) + (self.nota_prova))/2
return self.media
def escrever_situacao(self, nome_arquivo):
arq = open(nome_arquivo, 'w')
freq = ((80 - self.faltas)/80)*100
arq.write(self.ra+':'+self.nome+"\n")
arq.write(str("%.2f" % Aluno.mostrar_nota(self) + "\n"))
arq.write(str("%.1f" % freq)+"%"+"\n")
if Aluno.calcular_aprovacao(self) is True:
arq.write("Aprovado")
else:
arq.write("Reprovado")
Good Galera I made this code that simply takes the values of a file . txt does some calculations and creates another txt file with the media and whether it was approved or not. My only problem is that I am unable to assign the media account in my self.media attribute, I would like to know why, and I would also like to know if my code is more than I should. It’s been almost 1 year that I’m studying python.
Clarify better what you intended to happen and what is actually happening
– João Castilho