How to store multiple values read from the user?

0
aluno = int(input('Qual o numero de alunos ? '))
for i in range(aluno):
    nota = float(input('Insira a nota de cada um dos alunos: '))

I need to know how I store student grades to add and divide by the number of students entered into the program

    
asked by anonymous 25.10.2018 / 22:39

1 answer

4

You can use a list .

notas = []
aluno = int(input('Qual o numero de alunos ? '))
for i in range(aluno):
    nota = float(input('Insira a nota de cada um dos alunos: '))
    notas.append(nota)

And to calculate the mean, simply calculate the sum, sum() , and divide by the number of notes, len() :

media = sum(notas) / len(notas)  # Pode ser "aluno" no lugar do "len"

Or use the statistics package:

from statistics import mean

media = mean(notas)

See working code .

    
25.10.2018 / 22:47