Усильте обучение, добавив объяснения в программу викторины.Python

Программы на Python
Ответить
Anonymous
 Усильте обучение, добавив объяснения в программу викторины.

Сообщение Anonymous »

Я создаю программу викторины. Интересно, может ли кто-нибудь помочь мне, что изменить и как добавить подсказки в мою программу.
import random
from string import ascii_lowercase

def get_ext(file_type):
SAMPLE = {
'Who is the founder of Microsoft?': ['Bill Gates', 'Bill Clinton', 'Jeff Bezos', 'Elon Musk'],
'Who is the founder of Amazon?': ['Jeff Bezos', 'Bill Gates', 'Elon Musk', 'Joe Biden'],
'Who created Linux?': ['Linus Torvalds', 'Elon Musk', 'Bill Gates', 'Mark Zuckerberg']
}
return locals()[file_type]

def startQuiz():
try:
questionnaire = get_ext("SAMPLE")
tItems = (len(questionnaire))

except:
print ("Something is wrong")

questionPerStudent = min(3, len(questionnaire))
questionnaire = random.sample(list(questionnaire.items()), k=questionPerStudent)
num_correct = 0
currentQ = 0

for num, (questionnaire, alternatives) in enumerate(questionnaire, start=1):
print ("{}. {}".format(num,questionnaire))
currentQ += 1
correct_answer = alternatives[0]
labeled_alternatives = dict(zip(ascii_lowercase, random.sample(alternatives, k=len(alternatives))))
key_list = list(labeled_alternatives.keys())
val_list = list(labeled_alternatives.values())
position = val_list.index(str(correct_answer))
keychoice = key_list[position]

for label, alternative in labeled_alternatives.items():
print(f" {label}) {alternative}")

while (answer_label := input(" Your answer is? ")) not in labeled_alternatives:
print(f" Please answer one of {', '.join(labeled_alternatives)}")
answer = labeled_alternatives[answer_label]

if answer == correct_answer:
num_correct += 1
print(f"Correct : {keychoice}) {correct_answer}")

else:
print(f"Wrong Answer : {answer_label}) {answer}")
print(f"Correct Answer: {keychoice}) {correct_answer}")

startQuiz()

Текущий результат:
1. Who is the founder of Microsoft?
a) Jeff Bezos
b) Bill Gates
c) Elon Musk
d) Bill Clinton
Your answer is? a
Wrong Answer : a) Jeff Bezos
Correct Answer: b) Bill Gates

2. Who is the founder of Amazon?
a) Joe Biden
b) Elon Musk
c) Bill Gates
d) Jeff Bezos
Your answer is? a
Wrong Answer : a) Joe Biden
Correct Answer: d) Jeff Bezos

Я хотел добавить объяснение к каждому вопросу, например:
'Who is the founder of Microsoft?': ['Bill Gates', 'Bill Clinton', 'Jeff Bezos', 'Elon Musk'] info = "this is the explaination",

Какое изменение мне нужно, чтобы добавить объяснение в каждый вопрос и создать результат:
1. Who is the founder of Microsoft?
a) Jeff Bezos
b) Bill Gates
c) Elon Musk
d) Bill Clinton
Your answer is? a
Wrong Answer : a) Jeff Bezos
Correct Answer: b) Bill Gates

? this is the explanation


Подробнее здесь: https://stackoverflow.com/questions/785 ... iz-program
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»