Solução do Exercício - sistema de perguntas e respostas com Python

This commit is contained in:
Luiz Otávio
2022-11-02 12:54:57 -03:00
parent a7298a6205
commit 90bff56ea9

View File

@@ -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.')