According to the documentation, enumerate
returns a sequence of tuples containing the index and its element. Then for index in enumerate(lista_nota)
the variable index
is a tuple, and so gives this error when trying to use it in a comparison (if index > 7
).
But in case you seem to want to check just the amount, then you wouldn’t need to enumerate
.
Another detail is that you should just check the notes afterward all of which were typed (i.e., outside the while
). Finally, input
already returns a string, so do str(input(...))
is redundant and unnecessary.
And how are you using the pandas, can create the "Situation" column using apply
:
import pandas as pd
nomes = []
notas = []
while True:
print("=" * 10)
nomes.append(input(f"Nome: ").capitalize())
notas.append(float(input("Nota do aluno: ")))
print("=" * 10)
if input("Deseja continuar? [S/N]: ").upper()[0] == 'N':
break
df = pd.DataFrame({ "Nomes": nomes, "Nota": notas })
df['Situação'] = df.apply(lambda row: "APROVADO" if row['Nota'] > 7 else "REPROVADO", axis=1)
print(df)
I also changed the names of some variables. The lists of names and notes I named respectively nomes
and notas
, to give the idea that they may have more than one name and more than one note (you were using these names for the variables that only receive a name and note, and see that I deleted them, since they did not seem necessary, because they only serve to store the result of input
which is then added to the list, so I did it all in one step).
After the while
I check the status of each note, using apply
to create the "Situation" column, whose values are based on the note.
But if I were to use the for
in the list of notes, an alternative is to create another list of situations, thus:
nomes = []
notas = []
while True:
print("=" * 10)
nomes.append(input(f"Nome: ").capitalize())
notas.append(float(input("Nota do aluno: ")))
print("=" * 10)
if input("Deseja continuar? [S/N]: ").upper()[0] == 'N':
break
situacoes = []
for nota in notas:
situacoes.append("APROVADO" if nota > 7 else "REPROVADO")
df = pd.DataFrame({ "Nomes": nomes, "Nota": notas, "Situação": situacoes })
print(df)
Or, if you want you can change the lines of for
by a comprehensilist on:
situacoes = [ "APROVADO" if nota > 7 else "REPROVADO" for nota in notas ]