Re: gesucht wird eine kreative Methode um Sachaufgaben zu erstellen
Verfasst: Donnerstag 30. März 2023, 15:29
und was mache ich jetzt damit, damit ich es in der Datenbank speichern kann?
Seit 2002 Diskussionen rund um die Programmiersprache Python
https://www.python-forum.de/
Würde ich jetzt auch gruppieren, warum sollte man es anders machen?Pitwheazle hat geschrieben: ↑Donnerstag 30. März 2023, 15:56 4. Ich hatte an Aufgaben mit Division gedacht bei denen ja kein Rest entstehen soll wie z.B.
"Ein Sportler legt in 1 Stunde eine Strecke von 12 km zurück. Wie weit kommt er in 45 Minuten?" Da muss ich sicherstellen, dass alle Kombinationen von Strecke und Zeit sicher geteilt werden können und hätte sie gruppiert. Geht aber sicher auch anders.
Code: Alles auswählen
variablen_auswahl = {
"a": [
(1, 12, 45),
],
Code: Alles auswählen
class MathFormatter(string.Formatter):
def format_field(self, value, format_spec):
""" floats are formatted with comma.
There is a special format specifier for division with remainder.
{:r} only output there is a remainder
{:<d>r} output the remainder for division with <d> (e.g. {:15r}).
"""
if format_spec.endswith('r'):
result = format(value, '.0f')
if value % 1:
if format_spec == 'r':
result += " + Rest"
else:
rest = round((value % 1) * int(format_spec[:-1]))
result += f" + Rest {rest:d}"
else:
result = format(value, format_spec)
if format_spec.endswith('f') or isinstance(value, float):
result = result.replace('.', ',')
return result
def evaluate(self, format_string, **kwargs):
text = format_string.split('=')[0].format(**kwargs)
return Parser().evaluate(text, {})
text = "Wie viele {a}cm lange Stücke kann man von einer {b}m langen Leiste absägen?"
ergebnis = "100*{b} / {a} = {:{a}r}"
variablen_auswahl = {"a": [5,10,15,20,25], "b": [1,1.2,1.5,2,2.5]}
variablen = {
name: random.choice(werte)
for name, werte in variablen_auswahl.items()
}
formatter = MathFormatter()
loesung = formatter.evaluate(ergebnis, **variablen)
print(formatter.format(text, **variablen))
print(formatter.format(ergebnis, loesung, **variablen))
Code: Alles auswählen
variablen_auswahl = {
"a": [
('Julia', 'Sie', 'ihr'),
('Sophie', 'Sie', 'ihr'),
('Maria', 'Sie', 'ihr'),
('Paul', 'Er', 'ihm')],
"d": [
("einen neuen Pullover", "der"),
("eine neue Tasche", "die")],
"e": [10, 15, 20],
"f": [25, 28, 30]
}
print(json.dumps(variablen_auswahl))
habe ich hinbekommen. Auf den ersten Blick ändert das am Original nur die runden in eckige Klammern - ist es das oder gibt es noch was, das man (ich) nicht sieht?
Code: Alles auswählen
text = "Wie viele {a}cm lange Stücke kann man von einer {b}m langen Leiste absägen?"
loesung = "100*{b} / {a} = {:{a}r}"
variablen_auswahl = {"a": [15], "b": [1]}
text=aufgabe.text
loesung=aufgabe.loesung
frage = aufgabe.links_text
einheit = aufgabe.rechts_text
variablen = {
name: random.choice(werte)
for name, werte in variablen_auswahl.items()
}
formatter = MathFormatter()
ergebnis = formatter.evaluate(loesung, **variablen)
text = (formatter.format(text, **variablen))
lsg = (formatter.format(loesung, ergebnis, **variablen))
Code: Alles auswählen
class MathFormatter(string.Formatter):
def format_field(self, value, format_spec):
""" floats are formatted with comma.
There is a special format specifier for division with remainder.
{:r} only output there is a remainder
{:<d>r} output the remainder for division with <d> (e.g. {:15r}).
{:<d>c} output the number as a fraction with divisor <d>.
"""
if format_spec.endswith(('r', 'c')):
result = format(int(value), 'd')
if value % 1:
if format_spec == 'r':
result += " + Rest"
else:
divisor = int(format_spec[:-1])
rest = round((value % 1) * divisor)
if format_spec.endswith('r'):
result += f" + Rest {rest:d}"
else:
result += f" + {rest:d}/{divisor:d}"
else:
result = format(value, format_spec)
if format_spec.endswith('f') or isinstance(value, float):
result = result.replace('.', ',')
return result
def evaluate(self, format_string, **kwargs):
text = format_string.split('=')[0].format(**kwargs)
return Parser().evaluate(text, {})
Code: Alles auswählen
ergebnis = formatter.evaluate(loesung, **variablen)
if "r" in loesung.split("=")[1]:
ergebnis=ergebnis//1
lsg = (formatter.format(loesung, ergebnis, **variablen))
Mit
Code: Alles auswählen
pip install py_expression_eval
Code: Alles auswählen
> from py_expression_eval import Parser
> parser = Parser()
So, ich bin jetzt an Aufgaben mit diesem Problem.grubenfox hat geschrieben: ↑Donnerstag 30. März 2023, 16:24Würde ich jetzt auch gruppieren, warum sollte man es anders machen?Pitwheazle hat geschrieben: ↑Donnerstag 30. März 2023, 15:56 4. Ich hatte an Aufgaben mit Division gedacht bei denen ja kein Rest entstehen soll wie z.B.
"Ein Sportler legt in 1 Stunde eine Strecke von 12 km zurück. Wie weit kommt er in 45 Minuten?" Da muss ich sicherstellen, dass alle Kombinationen von Strecke und Zeit sicher geteilt werden können und hätte sie gruppiert. Geht aber sicher auch anders.Code: Alles auswählen
variablen_auswahl = { "a": [ (1, 12, 45), ],
Code: Alles auswählen
Ein Auto fährt mit einer Geschwindigkeit von {a}km/h. Wie lange braucht es, um eine Strecke von {b}km zurückzulegen?
{"a": [60,90],"b": [180]}