Erste Generatoren erstellt und hochgeladen.
This commit is contained in:
parent
80040048f5
commit
76e2de365d
121
aufgabengenerator_einheiten_umwandeln_2.py
Normal file
121
aufgabengenerator_einheiten_umwandeln_2.py
Normal file
@ -0,0 +1,121 @@
|
||||
import xml.etree.ElementTree as ET
|
||||
import random
|
||||
|
||||
# Einheiten mit ihren Umrechnungsfaktoren
|
||||
unit_conversion = {
|
||||
"t": {"factor": 1000, "name": "Kilogramm"},
|
||||
"kg": {"factor": 1000, "name": "Gramm"},
|
||||
"g": {"factor": 1000, "name": "Milligramm"},
|
||||
"ha": {"factor": 10000, "name": "Quadratmeter"},
|
||||
"m²": {"factor": 10000, "name": "Quadratcentimeter"},
|
||||
"a": {"factor": 100, "name": "Quadratmeter"},
|
||||
"m": {"factor": 1000, "name": "Millimeter"},
|
||||
"l": {"factor": 1000, "name": "Milliliter"},
|
||||
"ml": {"factor": 0.001, "name": "Liter"},
|
||||
"Tesla": {"factor": 1000000, "name": "Mikrotesla"},
|
||||
"Ampere": {"factor": 1000, "name": "Milliampere"},
|
||||
"Volt": {"factor": 1000, "name": "Millivolt"},
|
||||
"Coulomb": {"factor": 1000, "name": "Millikoulomb"},
|
||||
}
|
||||
|
||||
def create_conversion_question(name, questiontext, feedback, correct_answer, tolerance, unit_from, unit_to, tags):
|
||||
question = ET.Element('question', attrib={'type': 'numerical'})
|
||||
|
||||
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')
|
||||
text_elem.text = questiontext
|
||||
|
||||
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'
|
||||
|
||||
answer_elem = ET.SubElement(question, 'answer', attrib={'fraction': '100'})
|
||||
text_elem = ET.SubElement(answer_elem, 'text')
|
||||
text_elem.text = f"{str(correct_answer).replace('.', ',')} {unit_to}"
|
||||
|
||||
tolerance_elem = ET.SubElement(answer_elem, 'tolerance')
|
||||
tolerance_elem.text = str(tolerance).replace('.', ',')
|
||||
|
||||
feedback_elem = ET.SubElement(answer_elem, 'feedback', attrib={'format': 'html'})
|
||||
text_elem = ET.SubElement(feedback_elem, 'text')
|
||||
text_elem.text = 'Richtig!'
|
||||
|
||||
incorrectfeedback_elem = ET.SubElement(question, 'incorrectfeedback', attrib={'format': 'html'})
|
||||
text_elem = ET.SubElement(incorrectfeedback_elem, 'text')
|
||||
text_elem.text = 'Falsch.'
|
||||
|
||||
# Einheitsangabe hinzufügen
|
||||
units_elem = ET.SubElement(question, 'units')
|
||||
unit_elem = ET.SubElement(units_elem, 'unit')
|
||||
multiplier_elem = ET.SubElement(unit_elem, 'multiplier')
|
||||
multiplier_elem.text = '1'
|
||||
unit_name_elem = ET.SubElement(unit_elem, 'unit_name')
|
||||
unit_name_elem.text = unit_to
|
||||
|
||||
unitgradingtype_elem = ET.SubElement(question, 'unitgradingtype')
|
||||
unitgradingtype_elem.text = '1'
|
||||
|
||||
unitpenalty_elem = ET.SubElement(question, 'unitpenalty')
|
||||
unitpenalty_elem.text = '0.1000000'
|
||||
|
||||
showunits_elem = ET.SubElement(question, 'showunits')
|
||||
showunits_elem.text = '2'
|
||||
|
||||
unitsleft_elem = ET.SubElement(question, 'unitsleft')
|
||||
unitsleft_elem.text = '0'
|
||||
|
||||
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
|
||||
|
||||
questions = []
|
||||
|
||||
# Generiere 10 Umwandlungsfragen
|
||||
for i in range(1, 11):
|
||||
# Wähle eine Einheit und berechne die Umwandlung
|
||||
unit_from = random.choice(list(unit_conversion.keys()))
|
||||
unit_to = unit_conversion[unit_from]["name"].lower()
|
||||
conversion_factor = unit_conversion[unit_from]["factor"]
|
||||
|
||||
# Erstelle eine Zufallszahl zwischen einem kleinen Wert und einem größeren Wert
|
||||
number = round(random.uniform(0.001, 10.0), 5) # Beispielwert zwischen 0,001 und 10,0
|
||||
correct_answer = round(number * conversion_factor, 2)
|
||||
|
||||
questiontext = f"Runde {str(number).replace('.', ',')} {unit_from} auf die Einheit {unit_to} genau! (Bitte Einheit angeben!)"
|
||||
feedback = f"Die korrekte Antwort ist {str(correct_answer).replace('.', ',')} {unit_to}."
|
||||
tolerance = 0.0049
|
||||
tags = ["Runden", "Einheiten", "Umwandlung", "Physikalische Einheit"]
|
||||
|
||||
questions.append(create_conversion_question(f"Runden von {unit_from} nach {unit_to} {i}", questiontext, feedback, correct_answer, tolerance, unit_from, unit_to, tags))
|
||||
|
||||
# Erstelle das Quiz
|
||||
quiz = ET.Element('quiz')
|
||||
for q in questions:
|
||||
quiz.append(q)
|
||||
|
||||
# Speichere die XML-Datei
|
||||
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)
|
||||
|
||||
save_to_file(quiz, 'einheiten_umwandlung_quiz.xml')
|
||||
|
||||
print("Moodle-XML-Datei 'einheiten_umwandlung_quiz.xml' erfolgreich erstellt.")
|
181
aufgabengenerator_englisch_passiv_2objekte_v2.py
Normal file
181
aufgabengenerator_englisch_passiv_2objekte_v2.py
Normal file
@ -0,0 +1,181 @@
|
||||
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.")
|
231
aufgabengenerator_runden_v2.py
Normal file
231
aufgabengenerator_runden_v2.py
Normal file
@ -0,0 +1,231 @@
|
||||
import xml.etree.ElementTree as ET
|
||||
import random
|
||||
|
||||
units = ["m", "cm", "mm", "kg", "g", "L", "ml", "s", "ms"]
|
||||
|
||||
def create_multichoice_question(name, questiontext, feedback, answers, tags, unit):
|
||||
question = ET.Element('question', attrib={'type': 'multichoice'})
|
||||
|
||||
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')
|
||||
text_elem.text = questiontext
|
||||
|
||||
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'
|
||||
|
||||
single_elem = ET.SubElement(question, 'single')
|
||||
single_elem.text = 'true'
|
||||
|
||||
shuffleanswers_elem = ET.SubElement(question, 'shuffleanswers')
|
||||
shuffleanswers_elem.text = 'true'
|
||||
|
||||
answernumbering_elem = ET.SubElement(question, 'answernumbering')
|
||||
answernumbering_elem.text = 'abc'
|
||||
|
||||
correctfeedback_elem = ET.SubElement(question, 'correctfeedback', attrib={'format': 'html'})
|
||||
text_elem = ET.SubElement(correctfeedback_elem, 'text')
|
||||
text_elem.text = 'Richtig!'
|
||||
|
||||
partiallycorrectfeedback_elem = ET.SubElement(question, 'partiallycorrectfeedback', attrib={'format': 'html'})
|
||||
text_elem = ET.SubElement(partiallycorrectfeedback_elem, 'text')
|
||||
text_elem.text = 'Teilweise richtig. (Einheit fehlt oder ist falsch)'
|
||||
|
||||
incorrectfeedback_elem = ET.SubElement(question, 'incorrectfeedback', attrib={'format': 'html'})
|
||||
text_elem = ET.SubElement(incorrectfeedback_elem, 'text')
|
||||
text_elem.text = 'Falsch.'
|
||||
|
||||
for answer_text, fraction, feedback_text in answers:
|
||||
answer_elem = ET.SubElement(question, 'answer', attrib={'fraction': str(fraction), 'format': 'html'})
|
||||
text_elem = ET.SubElement(answer_elem, 'text')
|
||||
text_elem.text = answer_text
|
||||
|
||||
feedback_elem = ET.SubElement(answer_elem, 'feedback', attrib={'format': 'html'})
|
||||
text_elem = ET.SubElement(feedback_elem, 'text')
|
||||
text_elem.text = feedback_text
|
||||
|
||||
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
|
||||
|
||||
# Einheitsangabe hinzufügen
|
||||
units_elem = ET.SubElement(question, 'units')
|
||||
unit_elem = ET.SubElement(units_elem, 'unit')
|
||||
multiplier_elem = ET.SubElement(unit_elem, 'multiplier')
|
||||
multiplier_elem.text = '1'
|
||||
unit_name_elem = ET.SubElement(unit_elem, 'unit_name')
|
||||
unit_name_elem.text = unit
|
||||
|
||||
unitgradingtype_elem = ET.SubElement(question, 'unitgradingtype')
|
||||
unitgradingtype_elem.text = '1'
|
||||
|
||||
unitpenalty_elem = ET.SubElement(question, 'unitpenalty')
|
||||
unitpenalty_elem.text = '0.1000000'
|
||||
|
||||
showunits_elem = ET.SubElement(question, 'showunits')
|
||||
showunits_elem.text = '2'
|
||||
|
||||
unitsleft_elem = ET.SubElement(question, 'unitsleft')
|
||||
unitsleft_elem.text = '0'
|
||||
|
||||
return question
|
||||
|
||||
def create_numerical_question(name, questiontext, feedback, correct_answer, tolerance, unit, tags):
|
||||
question = ET.Element('question', attrib={'type': 'numerical'})
|
||||
|
||||
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')
|
||||
text_elem.text = questiontext
|
||||
|
||||
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'
|
||||
|
||||
answer_elem = ET.SubElement(question, 'answer', attrib={'fraction': '100'})
|
||||
text_elem = ET.SubElement(answer_elem, 'text')
|
||||
text_elem.text = f"{str(correct_answer).replace('.', ',')} {unit}"
|
||||
|
||||
tolerance_elem = ET.SubElement(answer_elem, 'tolerance')
|
||||
tolerance_elem.text = str(tolerance).replace('.', ',')
|
||||
|
||||
feedback_elem = ET.SubElement(answer_elem, 'feedback', attrib={'format': 'html'})
|
||||
text_elem = ET.SubElement(feedback_elem, 'text')
|
||||
text_elem.text = 'Richtig!'
|
||||
|
||||
incorrectfeedback_elem = ET.SubElement(question, 'incorrectfeedback', attrib={'format': 'html'})
|
||||
text_elem = ET.SubElement(incorrectfeedback_elem, 'text')
|
||||
text_elem.text = 'Falsch.'
|
||||
|
||||
# Einheitsangabe hinzufügen
|
||||
units_elem = ET.SubElement(question, 'units')
|
||||
unit_elem = ET.SubElement(units_elem, 'unit')
|
||||
multiplier_elem = ET.SubElement(unit_elem, 'multiplier')
|
||||
multiplier_elem.text = '1'
|
||||
unit_name_elem = ET.SubElement(unit_elem, 'unit_name')
|
||||
unit_name_elem.text = unit
|
||||
|
||||
unitgradingtype_elem = ET.SubElement(question, 'unitgradingtype')
|
||||
unitgradingtype_elem.text = '1'
|
||||
|
||||
unitpenalty_elem = ET.SubElement(question, 'unitpenalty')
|
||||
unitpenalty_elem.text = '0.1000000'
|
||||
|
||||
showunits_elem = ET.SubElement(question, 'showunits')
|
||||
showunits_elem.text = '2'
|
||||
|
||||
unitsleft_elem = ET.SubElement(question, 'unitsleft')
|
||||
unitsleft_elem.text = '0'
|
||||
|
||||
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 5 Single-Choice-Fragen zum Runden auf ganze Zahlen
|
||||
for i in range(1, 6):
|
||||
number = round(random.uniform(1, 100), 2)
|
||||
unit = random.choice(units)
|
||||
rounded = round(number)
|
||||
wrong1 = rounded + random.choice([1, 2])
|
||||
wrong2 = rounded - random.choice([1, 2])
|
||||
if wrong1 == rounded:
|
||||
wrong1 += 1
|
||||
if wrong2 == rounded:
|
||||
wrong2 -= 1
|
||||
answers = [
|
||||
(f"{rounded} {unit}", 100, "Richtig!"),
|
||||
(f"{wrong1} {unit}", 0, "Falsch."),
|
||||
(f"{wrong2} {unit}", 0, "Falsch.")
|
||||
]
|
||||
questiontext = f"Runde {str(number).replace('.', ',')} {unit} auf die nächste ganze Zahl. (Bitte Einheit angeben!)"
|
||||
feedback = f"Die korrekte Antwort ist {rounded} {unit}."
|
||||
tags = ["Runden", "Dezimalbrüche", "Ganze Zahl", "Physikalische Einheit"]
|
||||
questions.append(create_multichoice_question(f"Runden von Dezimalbrüchen {i}", questiontext, feedback, answers, tags, unit))
|
||||
|
||||
# Generiere 5 Single-Choice-Fragen zum Runden auf eine Dezimalstelle
|
||||
for i in range(6, 11):
|
||||
number = round(random.uniform(1, 100), 2)
|
||||
unit = random.choice(units)
|
||||
rounded = round(number, 1)
|
||||
wrong1 = round(number + random.uniform(0.1, 0.2), 1)
|
||||
wrong2 = round(number - random.uniform(0.1, 0.2), 1)
|
||||
answers = [
|
||||
(f"{str(rounded).replace('.', ',')} {unit}", 100, "Richtig!"),
|
||||
(f"{str(wrong1).replace('.', ',')} {unit}", 0, "Falsch."),
|
||||
(f"{str(wrong2).replace('.', ',')} {unit}", 0, "Falsch.")
|
||||
]
|
||||
questiontext = f"Runde {str(number).replace('.', ',')} {unit} auf eine Dezimalstelle. (Bitte Einheit angeben!)"
|
||||
feedback = f"Die korrekte Antwort ist {str(rounded).replace('.', ',')} {unit}."
|
||||
tags = ["Runden", "Dezimalbrüche", "Eine Dezimalstelle", "Physikalische Einheit"]
|
||||
questions.append(create_multichoice_question(f"Runden von Dezimalbrüchen {i}", questiontext, feedback, answers, tags, unit))
|
||||
|
||||
# Generiere 5 numerische Fragen zum Runden auf zwei Dezimalstellen
|
||||
for i in range(11, 16):
|
||||
number = round(random.uniform(1, 100), 3)
|
||||
unit = random.choice(units)
|
||||
rounded = round(number, 2)
|
||||
questiontext = f"Runde {str(number).replace('.', ',')} {unit} auf zwei Dezimalstellen. (Bitte Einheit angeben!)"
|
||||
feedback = f"Die korrekte Antwort ist {str(rounded).replace('.', ',')} {unit}."
|
||||
tolerance = 0.0049
|
||||
tags = ["Runden", "Dezimalbrüche", "Zwei Dezimalstellen", "Physikalische Einheit"]
|
||||
questions.append(create_numerical_question(f"Runden von Dezimalbrüchen {i}", questiontext, feedback, rounded, tolerance, unit, tags))
|
||||
|
||||
# Generiere 5 numerische Fragen zum Runden auf drei Dezimalstellen
|
||||
for i in range(16, 21):
|
||||
number = round(random.uniform(1, 100), 4)
|
||||
unit = random.choice(units)
|
||||
rounded = round(number, 3)
|
||||
questiontext = f"Runde {str(number).replace('.', ',')} {unit} auf drei Dezimalstellen. (Bitte Einheit angeben!)"
|
||||
feedback = f"Die korrekte Antwort ist {str(rounded).replace('.', ',')} {unit}."
|
||||
tolerance = 0.00049
|
||||
tags = ["Runden", "Dezimalbrüche", "Drei Dezimalstellen", "Physikalische Einheit"]
|
||||
questions.append(create_numerical_question(f"Runden von Dezimalbrüchen {i}", questiontext, feedback, rounded, tolerance, unit, tags))
|
||||
|
||||
quiz = create_quiz(questions)
|
||||
save_to_file(quiz, 'runden_von_dezimalbruechen_quiz.xml')
|
||||
|
||||
print("Moodle-XML-Datei 'runden_von_dezimalbruechen_quiz.xml' erfolgreich erstellt.")
|
Loading…
Reference in New Issue
Block a user