Я создаю программу викторины. Интересно, может ли кто-нибудь помочь мне, что изменить и как добавить подсказки в мою программу.
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
Усильте обучение, добавив объяснения в программу викторины. ⇐ Python
Программы на Python
-
Anonymous
1767807655
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
Подробнее здесь: [url]https://stackoverflow.com/questions/78501514/enforce-learning-by-adding-explanation-in-quiz-program[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия