Solução do Exercício - sistema de perguntas e respostas com Python
This commit is contained in:
37
aula77.py
37
aula77.py
@@ -18,3 +18,40 @@ perguntas = [
|
||||
'Resposta': '5',
|
||||
},
|
||||
]
|
||||
|
||||
qtd_acertos = 0
|
||||
for pergunta in perguntas:
|
||||
print('Pergunta:', pergunta['Pergunta'])
|
||||
print()
|
||||
|
||||
opcoes = pergunta['Opções']
|
||||
for i, opcao in enumerate(opcoes):
|
||||
print(f'{i})', opcao)
|
||||
print()
|
||||
|
||||
escolha = input('Escolha uma opção: ')
|
||||
|
||||
acertou = False
|
||||
escolha_int = None
|
||||
qtd_opcoes = len(opcoes)
|
||||
|
||||
if escolha.isdigit():
|
||||
escolha_int = int(escolha)
|
||||
|
||||
if escolha_int is not None:
|
||||
if escolha_int >= 0 and escolha_int < qtd_opcoes:
|
||||
if opcoes[escolha_int] == pergunta['Resposta']:
|
||||
acertou = True
|
||||
|
||||
print()
|
||||
if acertou:
|
||||
qtd_acertos += 1
|
||||
print('Acertou 👍')
|
||||
else:
|
||||
print('Errou ❌')
|
||||
|
||||
print()
|
||||
|
||||
|
||||
print('Você acertou', qtd_acertos)
|
||||
print('de', len(perguntas), 'perguntas.')
|
||||
|
||||
Reference in New Issue
Block a user