Elaborate a program to read a feedback with ten python objective questions

Asked

Viewed 981 times

-2

Elaborate a program to read a template with ten objective questions provided as a string with ten characters relative to the correct alternatives (each answer is indicated by ːA' or 'a', ?B' or 'b', ?C' or 'c', ’D' or’d' or 'e') . Ex.: If "DCBEACDDEA" is typed this means that the correct alternatives are: 1a. question’D', 2a. 'C', 3a. 'B', etc.

Obs. The program must repeat the reading of the full feedback if it is typed with an error (e.g., number of questions or an invalid character).

After reading the feedback, the program reads 5 answers of tests, also as strings, evaluates and writes the note of each of them. Each note is 0 to 10 (i.e., determined by a point for each item of the test response that checks with the template).

If there is an error in typing the test to be evaluated, the program writes a message stating that it cannot assign a note for this reason.

In addition to the main program, there should be functions for:
- feedback reading
- reading the answers
- assessment of responses
- note printing

I tried to make guys but I have no idea how to solve this, I could not do if someone can help me at least give a light to how I solve this thank you.

  • Instead of writing the program in Python, you could write the algorithm in plain text that describes the solution?

  • Do you want to read the answers in the scanned image of the template? If it is, it is not at all easy and you will need to study computer vision.

1 answer

1

Usually here answer more specific questions about programs already started, when you do not know where to go from a point.

Even so, I will try to give some tips: the main functionality normally neglected by beginners in programming, in any language, are the "functions". You must have learned how to create and use one in Python (with the command def).

From there, if you divide every different thing your program has to do for one function - as small as possible, and put together a main function to "orchestrate" the call of the others, the thing starts to get simpler.

Even for the program "talk to the world" - in this case, read typed strings and print answers, it uses functions. In this case, it is the predefined functions ("builtin") of Python: print and input (you should also have learned).

With functions, the command for the repeat loop for, and the command to execute code depending on a condition (if) You can do any show. And I also speak programs that serve web pages, design windows, games, etc... - the only difference is that in these cases you will need to use functions (sometimes third party) to "talk" to the world differently. ( Functions to create a text field in a window, and read what is typed there instead of input read only from the terminal, for example).

Of course the Python language and all the others will much besides the def, for and if - and this allows you to create shorter, more expressive, more organized programs. But with these 3 you do everything.

So in this case, you should start thinking about a skeleton of your program - and then what each function will do. If you don’t understand well how a function receives parameters and returns a result - this you need to study. I recommend using Python in interactive mode.

def ler_gabarito(comprimento, alternativas):
   correto = True
   entrada = input("Digite o gabarito: ")
   if len(entrada) != comprimento:
       print(f"São {comprimento} questões! Digite o número certo de respostas")
       correto = False
   for letra in entrada:
       if letra not in alternativas:
            print(f"A letra {letra}  não é uma alternativa válida")
            correto = False
   if correto:  # (nunca precisa fazer 'variavel == True')
       return entrada
   # se não estiver bom, chama a mesma função de novo e retorna seu resultado
   return ler_gabarito(comprimento, alternativas)   

def le_resposta(gabarito):
   ...
   nota = 0
   for i in range(len(gabarito)):
       ...
   print(nota)

def principal():
    gabarito = ler_gabarito(..., ...)
    for i in range(5):
       le_resposta(gabarito)

principal()
  • I put the first function on the whole - but it can get simpler if you use the while instead of just if for example. In the function that corrects proofs, read about the function zip Python to look more elegant.

Browser other questions tagged

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