From 03da57d74da6a24ba873a5ceb90bfb9c1b8ae4b0 Mon Sep 17 00:00:00 2001 From: Joshua Luckey Date: Sun, 22 Sep 2024 22:42:58 +0200 Subject: [PATCH] moved the solutions to the end, the detail tags are expanded in the html export --- python/python.ipynb | 293 ++++++++++++++++++++++++++------------------ 1 file changed, 172 insertions(+), 121 deletions(-) diff --git a/python/python.ipynb b/python/python.ipynb index 58764778..6d110b77 100644 --- a/python/python.ipynb +++ b/python/python.ipynb @@ -387,26 +387,7 @@ "3. Prüfe, ob des Objekt bereits über einen Meter gefallen ist.\n", "\n", "\n", - "\n", - "
\n", - "Lösung\n", - " \n", - "```\n", - "# 1.\n", - "t = 0.5\n", - "h_i = 10\n", - "v_i = 0.75\n", - "a_i = -9.81\n", - "\n", - "# 2.\n", - "h = h_i + v_i * t + 1/2 * a_i * t**2 \n", - "v = v_i * t + a_i * t \n", - "a = a_i\n", - "\n", - "# 3.\n", - "h < 9\n", - "```\n", - "
\n" + "Die Lösungen für die Kurzaufgaben sind am Ende dieser Datei." ] }, { @@ -552,32 +533,7 @@ "source": [ "### Kurzaufgaben 4\n", "4. Nutze die `print`-Funktion, um die gegebenen Startwerte \n", - "und die Ergebnisse der letzten Kurzaufgabe mit Überschritfen zu versehen und auszugeben.\n", - "\n", - "
\n", - "Lösung\n", - " \n", - "```\n", - "# 4.\n", - "print(\"Start...\")\n", - "print(\"...höhe\")\n", - "print(h_i)\n", - "print(\"...geschwindigkeit\")\n", - "print(v_i)\n", - "print(\"...beschleunigung\")\n", - "print(a_i)\n", - "\n", - "print(\"Nach der Zeit t\")\n", - "print(t)\n", - "print(\"Höhe\")\n", - "print(h)\n", - "print(\"Geschwindigkeit\")\n", - "print(v)\n", - "print(\"Beschleunigung\")\n", - "print(a)\n", - "\n", - "```\n", - "
\n" + "und die Ergebnisse der letzten Kurzaufgabe mit Überschritfen zu versehen und auszugeben." ] }, { @@ -850,37 +806,7 @@ " b) die Ergebnisse an die zugehörige Liste anhängst\n", " \n", " \n", - " Gibt die Listen H, V, A mit der `print`-Funktion aus\n", - "\n", - "\n", - "
\n", - "Lösung\n", - " \n", - "```\n", - "# 5.\n", - "T = [0.5, 1, 1.5]\n", - "H = []\n", - "V = []\n", - "A = []\n", - "\n", - "\n", - "H.append(h_i + v_i * T[0] + 1/2 * a_i * T[0]**2)\n", - "H.append(h_i + v_i * T[1] + 1/2 * a_i * T[1]**2)\n", - "H.append(h_i + v_i * T[2] + 1/2 * a_i * T[2]**2)\n", - "\n", - "V.append(v_i * T[0] + a_i * T[0])\n", - "V.append(v_i * T[1] + a_i * T[1])\n", - "V.append(v_i * T[2] + a_i * T[2])\n", - "\n", - "A.append(a_i)\n", - "A.append(a_i)\n", - "A.append(a_i)\n", - "\n", - "print(H)\n", - "print(V)\n", - "print(A)\n", - "```\n", - "
\n" + " Gibt die Listen H, V, A mit der `print`-Funktion aus\n" ] }, { @@ -986,25 +912,7 @@ "7. Greife auf die folgenden Werte im Dictionary zu:\n", "- der zweite Wert von t\n", "- der erste Wert von v\n", - "- der letzte Wert von h\n", - "\n", - "\n", - "
\n", - "Lösung\n", - " \n", - "```\n", - "# 6.\n", - "data = {\"t\":T, \"h\": H, \"v\": V, \"a\":A}\n", - "print(data)\n", - "\n", - "\n", - "# 7.\n", - "print(data[\"t\"][1])\n", - "print(data[\"v\"][0])\n", - "print(data[\"h\"][-1])\n", - "\n", - "```\n", - "
" + "- der letzte Wert von h\n" ] }, { @@ -1438,15 +1346,7 @@ "Schleife verwenden.\n", "\n", "Gib data mit der `print`-Funktion aus.\n", - "\n", - "\n", - "
\n", - "Lösung\n", - " \n", - "```\n", - "\n", - "```\n", - "
" + "\n" ] }, { @@ -1715,22 +1615,6 @@ "a -9.81 -9.81 -9.81 -9.81 -9.81 -9.81\n", "```\n", "Jede Zeile der Tabelle kann dabei durch Verwendung eines f-Strings formatiert werden.\n", - "\n", - "
\n", - "Lösung\n", - " \n", - "```\n", - "for k,v in data.items():\n", - " print(f\"{k} {v[0]:.2f} {v[1]:.2f} {v[2]:.2f} {v[3]:.2f} {v[4]:.2f} {v[5]:.2f}\")\n", - "\n", - "# Am Dezimaltrennzeichen ausgerichtet\n", - "\n", - "for k,v in data.items():\n", - " print(f\"{k} {v[0]:6.2f} {v[1]:6.2f} {v[2]:6.2f} {v[3]:6.2f} {v[4]:6.2f} {v[5]:6.2f}\")\n", - "```\n", - "\n", - "
\n", - "\n", "\n" ] }, @@ -2208,6 +2092,173 @@ "die vorher definiert wurden. Man kann dann interaktiv nach Problemen im Code suchen\n", "oder wie hier herausfinden wie Code funktioniert." ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Lösungen für die Kurzaufgaben\n", + "\n", + "
\n", + "Lösung zu 1., 2. und 3.\n", + " \n", + "```\n", + "# 1.\n", + "t = 0.5\n", + "h_i = 10\n", + "v_i = 0.75\n", + "a_i = -9.81\n", + "\n", + "# 2.\n", + "h = h_i + v_i * t + 1/2 * a_i * t**2 \n", + "v = v_i * t + a_i * t \n", + "a = a_i\n", + "\n", + "# 3.\n", + "h < 9\n", + "```\n", + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "Lösung zu 4.\n", + " \n", + "```\n", + "# 4.\n", + "print(\"Start...\")\n", + "print(\"...höhe\")\n", + "print(h_i)\n", + "print(\"...geschwindigkeit\")\n", + "print(v_i)\n", + "print(\"...beschleunigung\")\n", + "print(a_i)\n", + "\n", + "print(\"Nach der Zeit t\")\n", + "print(t)\n", + "print(\"Höhe\")\n", + "print(h)\n", + "print(\"Geschwindigkeit\")\n", + "print(v)\n", + "print(\"Beschleunigung\")\n", + "print(a)\n", + "\n", + "```\n", + "
\n", + "\n", + "\n", + "
\n", + "Lösung zu 5.\n", + " \n", + "```\n", + "# 5.\n", + "T = [0.5, 1, 1.5]\n", + "H = []\n", + "V = []\n", + "A = []\n", + "\n", + "\n", + "H.append(h_i + v_i * T[0] + 1/2 * a_i * T[0]**2)\n", + "H.append(h_i + v_i * T[1] + 1/2 * a_i * T[1]**2)\n", + "H.append(h_i + v_i * T[2] + 1/2 * a_i * T[2]**2)\n", + "\n", + "V.append(v_i * T[0] + a_i * T[0])\n", + "V.append(v_i * T[1] + a_i * T[1])\n", + "V.append(v_i * T[2] + a_i * T[2])\n", + "\n", + "A.append(a_i)\n", + "A.append(a_i)\n", + "A.append(a_i)\n", + "\n", + "print(H)\n", + "print(V)\n", + "print(A)\n", + "```\n", + "
\n", + "\n", + "\n", + "
\n", + "Lösung zu 6. und 7.\n", + " \n", + "```\n", + "# 6.\n", + "data = {\"t\":T, \"h\": H, \"v\": V, \"a\":A}\n", + "print(data)\n", + "\n", + "\n", + "# 7.\n", + "print(data[\"t\"][1])\n", + "print(data[\"v\"][0])\n", + "print(data[\"h\"][-1])\n", + "\n", + "```\n", + "
\n", + "\n", + "\n", + "
\n", + "Lösung zu 8. und 9.\n", + " \n", + "```\n", + "# 8.\n", + "def h(t):\n", + " return h_i + v_i * t + 1/2 * a_i * t**2\n", + "\n", + "\n", + "def v(t):\n", + " return v_i * t + a_i * t\n", + "\n", + "\n", + "def a(t):\n", + " return a_i\n", + "\n", + "\n", + "# 9.\n", + "\n", + "T = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5]\n", + "\n", + "# ohne Schleife\n", + "data = {\"t\":T, \"h\": [h(T[0]),h(T[1]),h(T[2]),h(T[3]),h(T[4]),h(T[5])],\n", + " \"v\": [v(T[0]),v(T[1]),v(T[2]),v(T[3]),v(T[4]),v(T[5])],\n", + " \"a\": [a(T[0]),a(T[1]),a(T[2]),a(T[3]),a(T[4]),a(T[5])]}\n", + "\n", + "print(data)\n", + "\n", + "\n", + "# mit Schleife\n", + "H = []\n", + "V = []\n", + "A = []\n", + "\n", + "for t in T:\n", + " H.append(h(t))\n", + " V.append(v(t))\n", + " A.append(a(t))\n", + "\n", + "\n", + "data = {\"t\":T, \"h\": H, \"v\": V, \"a\": A}\n", + "print(data)\n", + "\n", + "```\n", + "
\n", + "\n", + "\n", + "
\n", + "Lösung zu 10.\n", + " \n", + "```\n", + "for k,v in data.items():\n", + " print(f\"{k} {v[0]:.2f} {v[1]:.2f} {v[2]:.2f} {v[3]:.2f} {v[4]:.2f} {v[5]:.2f}\")\n", + "\n", + "# Am Dezimaltrennzeichen ausgerichtet\n", + "\n", + "for k,v in data.items():\n", + " print(f\"{k} {v[0]:6.2f} {v[1]:6.2f} {v[2]:6.2f} {v[3]:6.2f} {v[4]:6.2f} {v[5]:6.2f}\")\n", + "```\n", + "\n", + "
\n" + ] } ], "metadata": {