Runtime error in python 3.8 - URI

Asked

Viewed 241 times

1

I’m practicing some examples in the URI Online Judge and I’ve come up with this example:

inserir a descrição da imagem aqui

And I tried the following solution:

numeros = input().split();
N1, N2, N3, N4 = float(numeros[0]), float(numeros[1]), float(numeros[2]), float(numeros[3])

NotaExame = float(input())

M = (N1 * 2 + N2 * 3 + N3 * 4 + N4) / 10
print("Media:", M)

if M >= 7:
    print("Aluno aprovado.")
elif M < 5:
    print("Aluno reprovado.")
elif 5 <= M <= 6.9:
    print("Aluno em exame.")
    print("Nota do exame:", NotaExame)

    NovaMedia = (M + NotaExame) / 2

    if NovaMedia >= 5:
        print("Aluno aprovado.")
    else:
        print("Aluno reprovado.")

    print("Media final:", NovaMedia)

However, I got the following error on line 4:

RUNTIME ERROR

Traceback (most recent call last):
  File "Main.py", line 4, in 
    NotaExame = float(input())
EOFError: EOF when reading a line

The URI is very rigid in its inputs and outputs identical to how it wishes.

I put that Notaexame why put inside the elif line 13 (Because the example leaves to understand that this entry is to occur only if the student stay in condition to perform the exam) eventually resulting in Wrong Answer (5%), so I thought I’d try to fix the Runtime Error, that I believe is closer to the result.

1 answer

0


The statement makes it clear that the exam grade is only provided if the student is on the exam. Otherwise, there’ll be nothing to read, so you’ll make a mistake trying to use input. Then move the reading of the exam note into the specific condition (if it was wrong, it was for another reason).

Anyway, we can also change the if's:

n1, n2, n3, n4 = map(float, input().split())
media = (2 * n1 + 3 * n2 + 4 * n3 + n4) / 10
print(f'Media: {media:.1f}')

if media < 5:
    print('Aluno reprovado.')
elif media < 7:
    print('Aluno em exame.')
    exame = float(input())
    print(f'Nota do exame: {exame:.1f}')
    media = (media + exame) / 2
    if media >= 5:
        print('Aluno aprovado.')
    else:
        print('Aluno reprovado.')
    print(f'Media final: {media:.1f}')
else:
    print('Aluno aprovado.')

First I test if the average is less than 5. If not enter the first if, is because it is definitely greater than or equal to 5, so I don’t need to test this again on elif (just see if it’s less than 7). If you didn’t enter the if nor in the elif, is because it is definitely greater than or equal to 7 so you do not need to test it again (if you arrived at the else is because it is approved).

Notice I used f-string (with a f before opening quotation marks) together with the format .1f to display numbers to 1 decimal place (one of the exercise requirements). Maybe this is what gave problem in your case, must have cases that the average gets more than one decimal, but the exercise asks that the notes are printed with only one house (as was not given the link, I can not test).

  • Friend, I will soon test your solution. I did not send the link, because to be able to perform the test and submit, there must be an account in the URI, but follow the link: https://www.urionlinejudge.com.br/judge/pt/problems/view/1040

Browser other questions tagged

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