-2
Good morning, you guys. I’m still a beginner in programming, I’m trying to write a simple program that calculates the coefficient of performance and reports the percentage of the course completed, but I’m having problems with a conditional if that is not being respected. The idea is as follows, if the student’s situation is approved, I have an auxiliary variable that sums the credits obtained in the discipline, but it is only to add if it has been approved, however my code is ignoring the conditional and adding everything. Can someone help me figure 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 section that the problem is. Below I will paste the whole code. It imports the notes from a txt file that has the amount of credits, the note and the situation. The txt file can be downloaded at https://drive.google.com/open?id=1TOjOD5ktD2eA0fEkkfFDg-HljuiKwHmN
Follows full 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)),"%")
It worked out! I still didn’t know the function strip(), I will write it down not to forget. Thank you very much.
– Cadu