0

(https://i.stack.imgur.com/a5RxM.png)

Is there any way to format the variable space media and make it 2 decimal places at the same time?

I want to keep the variable aligned.

CreepyRaccoon
  • 826
  • 1
  • 9
  • 19
Alan
  • 1
  • 1

1 Answers1

0

I think you were missing the formatting of the notes (as str) and the precision of the float:

print(f'{"Aluno":25}{"Notas":25}{"Média":25}')
print("-------------------------------------------------------")
for i, a in enumerate(alunos):
    media = sum(notas[i]) / len(notas[i])
    print(f'{a:25}{str(notas[i]):25}{media:.2f}')

Output:

Aluno                    Notas                    Média
José                     [10, 9, 8, 8]            8.75
Joana                    [9, 7, 6, 4]             6.50
Maria                    [10, 10, 10, 10]         10.00
...
...

See Format specifiers for more info.

CreepyRaccoon
  • 826
  • 1
  • 9
  • 19