How to calculate test scores?

Asked

Viewed 854 times

3

I’m writing a code that prints a student’s grade according to the number of questions he gets right. But I need the program to do the calculation in a specific amount of times. The program must receive the amount of questions in the test, the feedback of the test (the test is objective), the amount of students who took the test and the response of each student. The program must print each student’s grade, and the student receives 1 point for the correct question. Example:

Entree:

5
ABCDD
2
ABCDD
ACCDE

Exit:

5
3

Another example:

Entree:

3
DAA
3
ABA
DDA
BBC

Exit:

1
2
0

Like I’m doing:

questões = int(raw_input())
gabarito = raw_input()
alunos = int(raw_input())
resposta = raw_input()
nota = 0
for i in resposta:
   if i == r in gabarito:
      nota = nota + 1
   print nota

My difficulty is in getting the code to receive the specified number of entries. Would it be right to define a function, or not accurate? How to proceed?

  • I don’t understand that line: if i == r in gabarito . Also, your code does not run-- is without parentheses in raw_input.

  • If the answer item is contained in the template. Typing error.

  • Do you understand that you are looking for a Boolean inside a String on that line? Also, what is r?

  • I do not understand, I will study the subject. 'r' would be the variable representation of each item in the answer. I made a mistake. Thanks for the tips.

1 answer

2


In the question, it is a quantity x of students passed through the exercise, that’s where you’re missing.

When taking the amount of students who answered the feedback, have to enter a repetition structure to capture all students and after that check the feedback of each one.

Another thing, it got a little strange to your condition if i == r in gabarito, the in is used to search for the value within the string or array ex:

if 'msg' in "Name of message is msg, end of string":

The condition will seek to string "msg" inside the other string, then in the case of feedback, even if the order is wrong, the code would consider as correct.

Solved code:

#!/usr/bin/env python2.7
# o método input() recolhe valores inteiros, não há
# necessidade de conversão
# o raw_input() recolhe strings, mas só é disponível
# para o python2.x, no python3.x, só possui o método
# input() recolhendo string
quest = input()
gabar = raw_input()
aluno = input()

for x in range(aluno):
    resp = raw_input()
    nota = 0
    for x in range(len(resp)):
        if gabar[x] == resp[x]:
            nota+=1

    print nota

Browser other questions tagged

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