How to store various user read values?

Asked

Viewed 42 times

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 students' grades to add and divide by the number of students typed in the program

  • 1

    You know the structure list python?

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 average, just calculate the sum, sum(), and divided by the number of banknotes, len():

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

Or use the package statistics:

from statistics import mean

media = mean(notas)

See the code working.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.