From 90bff56ea9b47e25f599d4a04578575af8c30b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Wed, 2 Nov 2022 12:54:57 -0300 Subject: [PATCH] =?UTF-8?q?Solu=C3=A7=C3=A3o=20do=20Exerc=C3=ADcio=20-=20s?= =?UTF-8?q?istema=20de=20perguntas=20e=20respostas=20com=20Python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula77.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/aula77.py b/aula77.py index 3bf372c..c08fe25 100644 --- a/aula77.py +++ b/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.')