{ | |||||
"cells": [ | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"# Software Entwicklung \n", | |||||
"\n", | |||||
"## Kapitel 6: Mengen und Dictionaries" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"### 6.1 Mengen\n", | |||||
"\n", | |||||
"*Listen* sind keine *Mengen* im mathematischen Sinne, weil\n", | |||||
"\n", | |||||
"* die Elemente eine Reihenfolge besitzen (was bei Mengen im Allgeinen nicht der Fall ist)\n", | |||||
"* Elemente mehrfach in der Liste vorkommen können (was bei Mengen nicht möglich ist)\n", | |||||
"\n", | |||||
"Eine Liste kann mit Hilfe der Built-In-Funktion\n", | |||||
"<code>set</code> in eine Menge umgewandelt werden." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"menge = set([1, 2, 3])\n", | |||||
"print(type(menge))" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%% md\n" | |||||
}, | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Duplikate werden bereinigt, d.h. identische Werte sind anschließend nur einmal enthalten." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"menge = set([1, 1, 3])\n", | |||||
"print(len(menge))\n", | |||||
"print(menge)" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Da die Elemente in einer Menge keine Reihenfolge besitzen, ist der Zugriff mit Hilfe\n", | |||||
"eines Index nicht möglich." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"menge = set([1, 2, 3])\n", | |||||
"print(menge[1])" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Allerdings kann in der bekannten Form über eine Menge iteriert werden. Die Reihenfolge ist\n", | |||||
"nicht festgelegt und kann sich ggf. von Rechner zu Rechner unterscheiden." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"menge = set([1, 2, 3])\n", | |||||
"for zahl in menge:\n", | |||||
" print(zahl)" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Die Elemente in einem Set müssen einen unveränderlichen Datentyp besitzen, d.h. Listen\n", | |||||
"sind z.B. keine zulässigen Elemente eines Sets." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"liste1 = [1, 2]\n", | |||||
"liste2 = [3, 4]\n", | |||||
"\n", | |||||
"liste_der_listen = [liste1, liste2]\n", | |||||
"\n", | |||||
"menge = set(liste_der_listen)\n", | |||||
"print(len(menge))" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Bei Mengen in Python unterscheiden sich Gleichheit und Identität, d.h.\n", | |||||
"Mengen sind selbst auch veränderliche Datentypen." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"menge1 = set([])\n", | |||||
"menge2 = set([])\n", | |||||
"\n", | |||||
"if menge1 == menge2:\n", | |||||
" print(\"Gleich!\")\n", | |||||
"\n", | |||||
"if menge1 is menge2:\n", | |||||
" print(\"Identisch!\")" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Elemente können mit <code>add</code> hinzugefügt und mit <code>remove</code> entfernt werden." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"menge = set([1, 2, 3])\n", | |||||
"menge.add(2)\n", | |||||
"menge.remove(3)\n", | |||||
"for zahl in menge:\n", | |||||
" print(zahl)" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Die Überprüfung, ob ein Element in einer Menge ist, erfolgt wieder mit dem Operator <code>in</code>." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"menge = set([1, 2, 3])\n", | |||||
"if 4 in menge:\n", | |||||
" print(\"Enthalten!\")\n", | |||||
"liste = [1, 2, 3]\n", | |||||
"if 3 in liste:\n", | |||||
" print(\"E\")" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Aufgrund der Einschränkungen, die mit einer Menge verbunden sind (keine Reihenfolge,\n", | |||||
"jedes Element max. einmal enthalten), kann Python einige Operationen performanter ausführen\n", | |||||
"als bei einer Liste.\n", | |||||
"\n", | |||||
"Im nachfolgenden Beispiel erwartet <code>timeit</code> als erstes Argument eine\n", | |||||
"Funktion, die dann <code>number</code>-mal ausgeführt wird. Zurückgegeben wird die\n", | |||||
"Ausführungszeit.\n" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
}, | |||||
"slideshow": { | |||||
"slide_type": "subslide" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"import timeit\n", | |||||
"\n", | |||||
"liste = list(range(100000))\n", | |||||
"menge = set(liste)\n", | |||||
"\n", | |||||
"dauer_bei_liste = timeit.timeit(lambda:50000 in liste, number=10000)\n", | |||||
"print(f\"Liste {dauer_bei_liste}\")\n", | |||||
"\n", | |||||
"dauer_bei_menge = timeit.timeit(lambda:50000 in menge, number=10000)\n", | |||||
"print(f\"Menge {dauer_bei_menge}\")" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Darüber hinaus bietet eine Menge einige Mengenoperationen mittels Infix-Operator:\n", | |||||
"\n", | |||||
"* <code>&</code> liefert die Schnittmenge zweier Mengen\n", | |||||
"* <code>|</code> liefert die Vereinigungsmenge zweier Mengen\n", | |||||
"* <code>-</code> liefert die Differnzmenge, d.h. die erste Menge ohne die Elemente der zweiten Menge" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
}, | |||||
"slideshow": { | |||||
"slide_type": "subslide" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"menge1 = set([1, 2, 3])\n", | |||||
"menge2 = set([2, 4, 6])\n", | |||||
"\n", | |||||
"schnittmenge = menge1 & menge2\n", | |||||
"vereinigungsmenge = menge1 | menge2\n", | |||||
"differenzmenge = menge1 - menge2\n", | |||||
"\n", | |||||
"print(f\"Schnittmenge {schnittmenge}\")\n", | |||||
"print(f\"Vereinigungsmenge {vereinigungsmenge}\")\n", | |||||
"print(f\"Differenzmenge {differenzmenge}\")\n", | |||||
"print(f\"dd{1+2}dd\")\n", | |||||
"\n", | |||||
"text = \"dd{1+2}dd\"\n", | |||||
"print(len(text))\n" | |||||
] | |||||
} | |||||
], | |||||
"metadata": { | |||||
"celltoolbar": "Slideshow", | |||||
"kernelspec": { | |||||
"display_name": "Python 3 (ipykernel)", | |||||
"language": "python", | |||||
"name": "python3" | |||||
}, | |||||
"language_info": { | |||||
"codemirror_mode": { | |||||
"name": "ipython", | |||||
"version": 3 | |||||
}, | |||||
"file_extension": ".py", | |||||
"mimetype": "text/x-python", | |||||
"name": "python", | |||||
"nbconvert_exporter": "python", | |||||
"pygments_lexer": "ipython3", | |||||
"version": "3.9.9" | |||||
} | |||||
}, | |||||
"nbformat": 4, | |||||
"nbformat_minor": 1 | |||||
} |
{ | |||||
"cells": [ | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"# Software Entwicklung \n", | |||||
"\n", | |||||
"## Kapitel 6: Mengen und Dictionaries" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"### 6.2 Dictionaries\n", | |||||
"\n", | |||||
"Die bereits behandelten *Listen* sind bekanntlich eine Möglichkeit, beliebige\n", | |||||
"Werte mit Hilfe eines numerischen Zugriffsschlüssels, dem Index, zu verwalten.\n", | |||||
"Die Werte besitzen bei Listen damit eine Reihenfolge, d.h. mathematisch gesehen ist eine\n", | |||||
"Liste eine Abbildung $f$ von ganzzahligen Indexwerten auf eine beliebige Wertemenge $W$:\n", | |||||
"\n", | |||||
"$$f: N_0 \\rightarrow W$$\n", | |||||
"\n", | |||||
"\n", | |||||
"Dictionaries sind nun eine weitere Möglichkeit, beliebige Werte zu verwalten. Allerdings\n", | |||||
"verzichtet man auf die Reihenfolge zugunsten auch nicht-numerischer\n", | |||||
"Zugriffsschlüssel aus einer Schlüsselmenge $D$:\n", | |||||
"\n", | |||||
"$$f: D \\rightarrow W$$" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Im Gegensatz zu Listen, die mit eckigen Klammern (<code>[</code> und <code>]</code>) eingefasst\n", | |||||
"wurden, werden Dictionaries mit geschweiften Klammern (<code>{</code> und <code>}</code>) notiert.\n", | |||||
"\n", | |||||
"Da sich der Zugriffsschlüssel nicht mehr aus der Reihenfolge ergibt, muss er explizit angegeben\n", | |||||
"werden. Man spricht hier von *key*-*value* Paaren. In Python werden die Paare mit einem Doppelpunkt\n", | |||||
"getrennt, wobei *key* vor, und *value* nach dem Doppelpunkt angegeben wird.\n", | |||||
"\n", | |||||
"<code> \\< key \\> : \\< value \\> </code>\n" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"dict = { \"BMEI\" : \"Bachelor Medizintechnik Vertiefung EI\",\n", | |||||
" \"BMMF\" : \"Bachelor Medizintechnik Vertiefung MF\",\n", | |||||
" 17 : \"Hallo\",\n", | |||||
" True : \"Wahr\"}" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Der Zugriff auf die Elemente des Dictionaries erfolgt - wie auch bei der Liste - durch\n", | |||||
"Angabe des Zugriffsschlüssels in eckigen Klammern." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"print(dict[True])" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%% md\n" | |||||
}, | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Als Schlüssel sind nur unveränderliche Datentypen erlaubt. Listen oder Mengen sind\n", | |||||
"demnach keine zulässigen Schlüssel." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": {}, | |||||
"source": [ | |||||
"Der <code>in</code>-Operator überprüft bei einem Dictionary, ob der angefragte Wert als\n", | |||||
"*Schlüssel* im Dictionary enthalten ist." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"if \"BMEI\" in dict:\n", | |||||
" print(\"Als Schlüssel enthalten\")\n", | |||||
"if \"Bachelor Medizintechnik Vertiefung MF\" in dict:\n", | |||||
" print(\"Die Werte werden nicht durchsucht, daher sollte dieser Text nicht erscheinen\")\n" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%% md\n" | |||||
}, | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Mittels\n", | |||||
"\n", | |||||
"* <code>keys</code> kann eine Liste der Schlüssel\n", | |||||
"* <code>values</code> kann eine Liste der Werte\n", | |||||
"* <code>items</code> kann eine Liste von *key*-*value*-Tupeln\n", | |||||
"\n", | |||||
"extrahiert werden." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
}, | |||||
"slideshow": { | |||||
"slide_type": "subslide" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"print(list(dict.keys()))\n", | |||||
"print(list(dict.values()))\n", | |||||
"print(list(dict.items()))\n", | |||||
" " | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%% md\n" | |||||
}, | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Beim Iterieren über ein Dictionary wird die Schlüsselmenge durchlaufen." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"for element in dict:\n", | |||||
" print(element)" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%% md\n" | |||||
}, | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Der Zugriff auf die Werte kann dann über den Schlüssel erfolgen." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"for element in dict:\n", | |||||
" print(dict[element])" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Oder man iteriert gleich über die Wertemenge." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"for wert in dict.values():\n", | |||||
" print(wert)" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Das Löschen eines Eintrags in einem Dictionary erfolgt mit <code>del</code>." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"del(dict[\"BMEI\"])\n", | |||||
"print(dict)" | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"Das gesamte Dictionary wird mit <code>clear</code> geleert." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"name": "#%%\n" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"dict.clear()\n", | |||||
"print(dict)" | |||||
] | |||||
} | |||||
], | |||||
"metadata": { | |||||
"celltoolbar": "Slideshow", | |||||
"kernelspec": { | |||||
"display_name": "Python 3 (ipykernel)", | |||||
"language": "python", | |||||
"name": "python3" | |||||
}, | |||||
"language_info": { | |||||
"codemirror_mode": { | |||||
"name": "ipython", | |||||
"version": 3 | |||||
}, | |||||
"file_extension": ".py", | |||||
"mimetype": "text/x-python", | |||||
"name": "python", | |||||
"nbconvert_exporter": "python", | |||||
"pygments_lexer": "ipython3", | |||||
"version": "3.9.9" | |||||
} | |||||
}, | |||||
"nbformat": 4, | |||||
"nbformat_minor": 1 | |||||
} |
{ | |||||
"cells": [ | |||||
{ | |||||
"cell_type": "markdown", | |||||
"metadata": { | |||||
"collapsed": true, | |||||
"pycharm": { | |||||
"name": "#%% md\n" | |||||
}, | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"source": [ | |||||
"_Aufgabe 1_\n", | |||||
"\n", | |||||
"Schreiben Sie ein Python-Skript, das Studierende in einem Dictionary verwaltet. Schlüssel soll\n", | |||||
"die ganzzahlige Matrikelnummer sein, der Wert der Name des Studierenden.\n", | |||||
"\n", | |||||
"Ihr Skript soll dabei zunächst eine Matrikelnummer einlesen. Ist sie im Dictionary vorhanden,\n", | |||||
"soll der gespeicherte Name ausgegeben werden. Anschließend soll das Programm mit dem\n", | |||||
"Einlesen der nächsten Matrikelnummer fortgesetzt werden.\n", | |||||
"\n", | |||||
"Ist die Matrikelnummer nicht vorhanden, soll der Name eingelesen und im Dictionary gespeichert\n", | |||||
"werden. Anschließend geht es weiter mit der nächsten Matrikelnummer.\n", | |||||
"\n", | |||||
"Bei der Eingabe einer negativen Matrikelnummer soll der Studierende aus dem Dictionary\n", | |||||
"entfernt werden.\n", | |||||
"\n", | |||||
"Wird 0 eingegeben, endet das Programm." | |||||
] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [] | |||||
}, | |||||
{ | |||||
"cell_type": "code", | |||||
"execution_count": null, | |||||
"metadata": { | |||||
"pycharm": { | |||||
"is_executing": false, | |||||
"name": "#%%\n" | |||||
}, | |||||
"slideshow": { | |||||
"slide_type": "slide" | |||||
} | |||||
}, | |||||
"outputs": [], | |||||
"source": [ | |||||
"dict = {}\n", | |||||
"matrikel = None\n", | |||||
"\n", | |||||
"while matrikel != 0:\n", | |||||
" matrikel = int(input(\"Matrikelnummer: \"))\n", | |||||
" \n", | |||||
" if matrikel < 0:\n", | |||||
" del(dict[-matrikel])\n", | |||||
" elif matrikel in dict:\n", | |||||
" print(dict[matrikel])\n", | |||||
" elif matrikel > 0:\n", | |||||
" name = input(\"Name: \")\n", | |||||
" dict[matrikel] = name\n", | |||||
" \n", | |||||
"print(dict)" | |||||
] | |||||
} | |||||
], | |||||
"metadata": { | |||||
"celltoolbar": "Slideshow", | |||||
"kernelspec": { | |||||
"display_name": "Python 3 (ipykernel)", | |||||
"language": "python", | |||||
"name": "python3" | |||||
}, | |||||
"language_info": { | |||||
"codemirror_mode": { | |||||
"name": "ipython", | |||||
"version": 3 | |||||
}, | |||||
"file_extension": ".py", | |||||
"mimetype": "text/x-python", | |||||
"name": "python", | |||||
"nbconvert_exporter": "python", | |||||
"pygments_lexer": "ipython3", | |||||
"version": "3.9.9" | |||||
} | |||||
}, | |||||
"nbformat": 4, | |||||
"nbformat_minor": 1 | |||||
} |
body.rise-enabled div.inner_cell>div.input_area { | |||||
font-size: 150%; | |||||
} | |||||
body.rise-enabled div.output_subarea.output_text.output_result { | |||||
font-size: 150%; | |||||
} | |||||
body.rise-enabled div.output_subarea.output_text.output_stream.output_stdout { | |||||
font-size: 150%; | |||||
} | |||||
body.rise-enabled div.output_subarea.output_html.rendered_html.output_result { | |||||
font-size: 150%; | |||||
} | |||||
body.rise-enabled td { | |||||
font-size: 120%; | |||||
} | |||||
body.rise-enabled th { | |||||
font-size: 120%; | |||||
} |