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()
Instead of writing the program in Python, you could write the algorithm in plain text that describes the solution?
– Woss
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.
– edson alves