Python Note Release Exercise

Asked

Viewed 873 times

-2

Hi, I’m a beginner in programming, and I have a college exercise to do, I managed to do a part, but I don’t know how to program the rest of it.

It’s a three-note-release python program per student, and each student must have a field to specify their name and gender, that part I managed to do in the program that I put down there, but I don’t know how I would put in that program below the other part of the exercise, if anyone can help me with that, I would be very grateful.

The other part is like this:

Regarding notes, the program cannot accept notes with numbers greater than 10 and notes with numbers less than 0, it has to return a message to insert a note between 0 and 10.

Regarding the average, it has to be like this: average greater than or equal to 7: approved, average between 4 and 6.99: exam, average less than 4: failed (you do not need to print this part now, only at the end).

And then at the end of the program, I need you to show (print) the following things:

Total number of registered students

The percentage of passed, exam and failed students.

And also the amount of women approved, exam and failed and the amount of men approved, exam and failed.

ficha = list()
while True:
    nome = str(input("Insira um nome: "))
    sexo = str(input("Insira seu sexo [M/F]: "))
    nota1 = float(input("Insira a nota 1: "))
    nota2 = float(input("Insira a nota 2: "))
    nota3 = float(input("Insira a nota 3: "))
    media = (nota1 + nota2 + nota3) / 3
    ficha.append([nome, sexo, [nota1, nota2, nota3], media])
    resposta = str(input("Quer continuar? [S/N]"))
    if resposta in 'Nn':
        break

2 answers

1

This here my solution, remembering that there is no validation in the inputs of 'sex', the program meets the other part in which you reported. I hope it helps.

ficha = []

while True:

    nome = str(input("Insira um nome: "))
    sexo = str(input("Insira seu sexo [M/F]: "))

    nota1 = float(input("Insira a nota 1: "))
    while nota1 < 0 or nota1 > 10:
        print("Nota invalida, digite um numero entre 0 e 10")
        nota1 = float(input("Insira a nota 1: "))

    nota2 = float(input("Insira a nota 2: "))
    while nota2 < 0 or nota2 > 10:
        print("Nota invalida, digite um numero entre 0 e 10")
        nota2 = float(input("Insira a nota 2: "))

    nota3 = float(input("Insira a nota 3: "))
    while nota3 < 0 or nota3 > 10:
        print("Nota invalida, digite um numero entre 0 e 10")
        nota3 = float(input("Insira a nota 3: "))

    media = (nota1 + nota2 + nota3) / 3
    if media >= 7:
        status = "Aprovado"
    elif media < 7 and media >= 4:
        status = "Exame"
    else:
        status = "Reprovado"

    ficha.append([nome, sexo, [nota1, nota2, nota3], media, status])

    resposta = str(input("Quer continuar? [S/N]"))
    if resposta in 'Nn':
        break

tx_reprovados = 0

tx_exame = 0

tx_aprovado = 0

m_aprovado = 0

f_aprovado = 0

m_exame = 0

f_exame = 0

m_reprovado = 0

f_reprovado = 0

for i in range(0, len(ficha), 1):

    if ficha[i][4] == "Reprovado":
        tx_reprovados += 1
        if ficha[i][1] in 'Ff':
            f_reprovado += 1
        else:
            m_reprovado += 1

    elif ficha[i][4] == "Exame":
        tx_exame += 1
        if ficha[i][1] in 'Ff':
            f_exame += 1
        else:
            m_exame += 1

    elif ficha[i][4] == "Aprovado":
        tx_aprovado += 1
        if ficha[i][1] in 'Ff':
            f_aprovado += 1
        else:
            m_aprovado += 1


print("Taxas de status: ")

print(f'Alunos aprovados: {(tx_aprovado/len(ficha))*100}%')

print(f'Alunos para exame: {(tx_exame/len(ficha))*100}%')

print(f'Alunos reprovados: {(tx_reprovados/len(ficha))*100}%')

print('-' * 45)

print('Visualizacao por sexo:')

print(f'Alunas aprovadas: {f_aprovado}')

print(f'Alunas para exame: {f_exame}')

print(f'Alunas reprovadas: {f_reprovado}')

print('')

print(f'Alunos aprovados: {m_aprovado}')

print(f'Alunos para exame: {m_exame}')

print(f'Alunos reprovados: {m_reprovado}')
  • If you prefer you can take the code from git: https://github.com/pabloTecchio/lancament_notas_escolares

0

Regarding notes, the program cannot accept notes with numbers greater than 10 and notes with numbers less than 0, it has to return a message to insert a note between 0 and 10.

For that part you have to put conditionals, it could be that way:

if (nota1 > 10 OR nota1 < 0)
nota1 = float(input("inserir uma nota entre 0 e 10:"))
if (nota2 > 10 OR nota2 < 0)
nota2 = float(input("inserir uma nota entre 0 e 10:"))
if (nota > 10 OR nota3 < 0)
nota1 = float(input("inserir uma nota entre 0 e 10:"))

This is the idea, take a look and improve the rest. Most of the resolution is in the correct use of conditional.

  • I will try to implement this part in the code, thanks for the help (I was not that put the -1 in your reply)

Browser other questions tagged

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