mdlAufgabengeneratoren/aufgabengenerator_englisch_passiv_2objekte_v2.py

182 lines
7.3 KiB
Python
Raw Normal View History

import xml.etree.ElementTree as ET
def create_cloze_question(name, questiontext, correct_answers, wrong_answers, feedback, tags):
question = ET.Element('question', attrib={'type': 'cloze'})
name_elem = ET.SubElement(question, 'name')
text_elem = ET.SubElement(name_elem, 'text')
text_elem.text = name
questiontext_elem = ET.SubElement(question, 'questiontext', attrib={'format': 'html'})
text_elem = ET.SubElement(questiontext_elem, 'text')
# Erstelle den Cloze-Text
cloze_text = questiontext
for i in range(len(correct_answers)):
correct_answer = correct_answers[i]
wrong_answer, wrong_feedback = wrong_answers[i]
cloze_text = cloze_text.replace("______", f"{{1:SHORTANSWER:={correct_answer}#{feedback}~%0%{wrong_answer}#{wrong_feedback}}}", 1)
text_elem.text = cloze_text
generalfeedback_elem = ET.SubElement(question, 'generalfeedback', attrib={'format': 'html'})
text_elem = ET.SubElement(generalfeedback_elem, 'text')
text_elem.text = feedback
defaultgrade_elem = ET.SubElement(question, 'defaultgrade')
defaultgrade_elem.text = '1.0000000'
penalty_elem = ET.SubElement(question, 'penalty')
penalty_elem.text = '0.3333333'
hidden_elem = ET.SubElement(question, 'hidden')
hidden_elem.text = '0'
# Tags hinzufügen
tags_elem = ET.SubElement(question, 'tags')
for tag in tags:
tag_elem = ET.SubElement(tags_elem, 'tag')
text_elem = ET.SubElement(tag_elem, 'text')
text_elem.text = tag
return question
def create_quiz(questions):
quiz = ET.Element('quiz')
for q in questions:
quiz.append(q)
return quiz
def save_to_file(xml_element, filename):
tree = ET.ElementTree(xml_element)
with open(filename, 'wb') as f:
tree.write(f, encoding='utf-8', xml_declaration=True)
questions = []
# Generiere 30 Cloze-Fragen zum Thema Passiv mit zwei Objekten und Greater London
cloze_data = [
{
"name": "The Shard",
"questiontext": "The Shard ______ (to be) ______ (design) by Renzo Piano.",
"correct_answers": ["was", "designed"],
"wrong_answers": [
("is", "Using 'is' suggests the design is ongoing."),
("design", "'Design' is not the correct form; the past participle is 'designed'.")
],
"feedback": "Correct! The Shard was designed by Renzo Piano.",
"tags": ["Greater London", "Passiv", "Verben mit zwei Objekten"]
},
{
"name": "The O2 Arena",
"questiontext": "The O2 Arena ______ (to be) ______ (open) in 2000.",
"correct_answers": ["was", "opened"],
"wrong_answers": [
("is", "'Is' is not correct as it indicates ongoing action."),
("opens", "'Opens' does not fit the passive construction.")
],
"feedback": "Well done! The O2 Arena was opened in 2000.",
"tags": ["Greater London", "Passiv", "Verben mit zwei Objekten"]
},
{
"name": "Hampstead Heath",
"questiontext": "Hampstead Heath ______ (to be) ______ (visit) by many Londoners.",
"correct_answers": ["is", "visited"],
"wrong_answers": [
("was", "'Was' implies it was only visited in the past."),
("visits", "'Visits' is not a passive form.")
],
"feedback": "Good job! Hampstead Heath is visited by many Londoners.",
"tags": ["Greater London", "Passiv", "Verben mit zwei Objekten"]
},
{
"name": "Wembley Stadium",
"questiontext": "Wembley Stadium ______ (to be) ______ (renovate) in 2007.",
"correct_answers": ["was", "renovated"],
"wrong_answers": [
("is", "'Is' suggests it is being renovated currently."),
("renovates", "'Renovates' does not fit in passive voice.")
],
"feedback": "Correct! Wembley Stadium was renovated in 2007.",
"tags": ["Greater London", "Passiv", "Verben mit zwei Objekten"]
},
{
"name": "The Thames",
"questiontext": "The Thames ______ (to be) ______ (pollute) by various industries.",
"correct_answers": ["is", "polluted"],
"wrong_answers": [
("was", "'Was' suggests it was only polluted in the past."),
("pollutes", "'Pollutes' is incorrect in passive voice.")
],
"feedback": "Exactly! The Thames is polluted by various industries.",
"tags": ["Greater London", "Passiv", "Verben mit zwei Objekten"]
},
{
"name": "The West End",
"questiontext": "The West End ______ (to be) ______ (famous) for its theaters.",
"correct_answers": ["is", "famous"],
"wrong_answers": [
("was", "'Was' is not appropriate since it is still famous."),
("fame", "'Fame' is not the correct form here.")
],
"feedback": "Correct! The West End is famous for its theaters.",
"tags": ["Greater London", "Passiv", "Verben mit zwei Objekten"]
},
{
"name": "Hyde Park",
"questiontext": "Hyde Park ______ (to be) ______ (enjoy) by locals and tourists.",
"correct_answers": ["is", "enjoyed"],
"wrong_answers": [
("was", "'Was' is incorrect as it is enjoyed now."),
("enjoys", "'Enjoys' does not fit the passive construction.")
],
"feedback": "Well done! Hyde Park is enjoyed by locals and tourists.",
"tags": ["Greater London", "Passiv", "Verben mit zwei Objekten"]
},
{
"name": "The London Underground",
"questiontext": "The London Underground ______ (to be) ______ (use) by millions every day.",
"correct_answers": ["is", "used"],
"wrong_answers": [
("was", "'Was' does not accurately reflect the current usage."),
("uses", "'Uses' is not in the passive form.")
],
"feedback": "Good job! The London Underground is used by millions every day.",
"tags": ["Greater London", "Passiv", "Verben mit zwei Objekten"]
},
{
"name": "Buckingham Palace",
"questiontext": "Buckingham Palace ______ (to be) ______ (visit) by many tourists.",
"correct_answers": ["is", "visited"],
"wrong_answers": [
("was", "'Was' implies it was only visited in the past."),
("visits", "'Visits' is incorrect in passive voice.")
],
"feedback": "Exactly! Buckingham Palace is visited by many tourists.",
"tags": ["Greater London", "Passiv", "Verben mit zwei Objekten"]
},
{
"name": "The Science Museum",
"questiontext": "The Science Museum ______ (to be) ______ (see) by children and adults alike.",
"correct_answers": ["is", "seen"],
"wrong_answers": [
("was", "'Was' suggests it was only seen in the past."),
("sees", "'Sees' is not in the passive form.")
],
"feedback": "Correct! The Science Museum is seen by children and adults alike.",
"tags": ["Greater London", "Passiv", "Verben mit zwei Objekten"]
}
]
# Erstelle die Fragen basierend auf den Daten
for item in cloze_data:
questions.append(create_cloze_question(item["name"], item["questiontext"], item["correct_answers"], item["wrong_answers"], item["feedback"], item["tags"]))
# Erstelle das Quiz
quiz = create_quiz(questions)
# Speichere die XML-Datei
save_to_file(quiz, 'cloze_london_quiz2.xml')
print("Moodle-XML-Datei 'cloze_london_quiz2.xml' erfolgreich erstellt.")