Good morning, guys. I am still new to programming, I am trying to write a simple program, which calculates the coefficient of performance and report the percentage of the finished course, but I am having problems with an if conditional that is not being respected. The idea is this, if the student's situation is approved, I have an auxiliary variable that adds the credits obtained in the course, but only to add if it has been approved, however my code is ignoring the conditional and adding everything. Can anyone help me find out why this is happening?
for i in range(len(nota)):
if sit[i] == "aprovado\n" or "aprovado":
aux += (cred[i]) #Calcula o somatório dos créditos nas matérias onde se obteve aprovação.
It is in the above passage that there is the problem. Below I will paste the whole code. It imports the notes of a file type txt that has the amount of credits, the note and the situation. The txt file can be downloaded at link
Follow the complete code:
x = open('notas1.txt')
cred = []
nota = []
sit = []
cr = 0
sumcred = 0
totcred = 237 #Total de créditos do curso.
aux = 0
for line in x:
a = line.split(" ")
cred += [int(a[0])]
nota += [float(a[1])]
sit += [(a[2])]
for i in cred:
sumcred += sum([i]) #Calcula o somatório dos créditos cursados até o momento.
for i in range(len(nota)):
if sit[i] == "aprovado\n" or "aprovado":
aux += (cred[i]) #Calcula o somatório dos créditos nas matérias onde se obteve aprovação.
print(aux)
for i in range(len(cred)):
cr += cred[i]*nota[i] #Faz a multiplicação da nota obtida em cada disciplina pela quantidade de créditos.
print("O seu coeficiente de rendimento acumulado (CR) é igual a:",(round((cr/sumcred),2)))
print("O percentual concluído até o momento é de:",(round(((aux/totcred)*100),2)),"%")