Elaborate a program to read a template with ten objective questions python [closed]

-1

Develop a program to read a template with ten objective questions provided as a string with ten characters relative to the correct alternatives (each response is indicated by 'A' or 'a', 'B' or 'b', 'C' or 'c', 'D' or 'd' or 'E' or 'e'). Example: If "DCBEACDDEA" is entered, this means that the correct alternatives are: 1a. question 'D', 2a. 'C', 3a. 'B', etc. Home Obs. The program should repeat the complete template reading if it is typed with some error (eg number of questions or some invalid character). Home After reading the template, the program reads 5 test answers, also as strings, evaluates and writes the grade of each of them. Each note is from 0 to 10 (that is, determined by a point for each item of the test response that confers with the template.) If there is any typing error for the test to be evaluated, the program writes a message that you can not assign a note for this reason.

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

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

    
asked by anonymous 29.11.2018 / 13:49

1 answer

2

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

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

From there, if you split every different thing your program has to do for a function - as small as possible, and join a main function to "orchestrate" the call from the others, things start to get simpler. / p>

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

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

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

So in that case, you should start thinking about a skeleton in your program - and then what each function will do. If you do not quite understand 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()
    
29.11.2018 / 14:12