tuple1.append(1)# Tuples sind unveränderlich (immutable) daher können nicht einfach elemente angefügt werden
+
+
+
+
+
+
+
+
+
+
+
+
+
+---------------------------------------------------------------------------
+AttributeError Traceback (most recent call last)
+Cell In[40], line 1
+----> 1tuple1.append(1) # Tuples sind unveränderlich (immutable) daher können nicht einfach elemente angefügt werden
+
+AttributeError: 'tuple' object has no attribute 'append'
# Unterschiedlichen Code ausführen je nach Bedingung
+zahl=32
+ifzahl%2==1:# ist die zahl Gerade?
+ print("Ist Ungerade")# Wenn Ja
+else:
+ print("Ist Gerade")# Wenn Nein
+
+
+
+
+
+
+
+
+
+
+
+
+
Ist Gerade
+
+
+
+
+
+
+
+
+
+
+
In [47]:
+
+
+
# Argument "verneinen"
+zahl=32
+ifnotzahl%2==1:# Ist die zahl nicht gerade?
+ print("Ist Gerade")# Wenn Ja (Zahl nicht gerade -> Zahl gerade)
+else:
+ print("Ist Ungerade")# Wenn Nein
+
+
+
+
+
+
+
+
+
+
+
+
+
Ist Gerade
+
+
+
+
+
+
+
+
+
+
+
In [48]:
+
+
+
if42%2==0and36%2==1:# Und verknüpfung alle bedingungen müssen wahr sein
+ print("Sind beide Gerade")
+
+
+
+
+
+
+
+
+
+
+
In [49]:
+
+
+
TrueandFalse
+
+
+
+
+
+
+
+
+
+
+
Out[49]:
+
+
False
+
+
+
+
+
+
+
+
+
+
In [50]:
+
+
+
if42%2==0or36%2==1:# Oder Verknüpfung eine oder mehrere Bedingungen müssen wahr sein
+ print("Eine Zahl ist Gerade")
+
+
+
+
+
+
+
+
+
+
+
+
+
Eine Zahl ist Gerade
+
+
+
+
+
+
+
+
+
+
+
In [51]:
+
+
+
TrueorFalse
+
+
+
+
+
+
+
+
+
+
+
Out[51]:
+
+
True
+
+
+
+
+
+
+
+
+
+
In [52]:
+
+
+
FalseorFalse
+
+
+
+
+
+
+
+
+
+
+
Out[52]:
+
+
False
+
+
+
+
+
+
+
+
+
+
In [53]:
+
+
+
TrueorTrue
+
+
+
+
+
+
+
+
+
+
+
Out[53]:
+
+
True
+
+
+
+
+
+
+
+
+
+
In [54]:
+
+
+
# Verschiedene Bedingungen mit verschiedenen Ausgaben
+zahl=10
+
+ifzahl%3==0:# zahl durch 3 teilbar?
+ print("Zahl ist durch 3 glatt teilbar")
+elifzahl%5==0:# Zahl durch 5 teilbar?
+ print("Zahl ist durch 5 glatt teilbar")
+else:# Weder noch (Base Case)
+ print("Zahl ist nicht durch 3 oder 5 teilbar")
+
+
+
+
+
+
+
+
+
+
+
+
+
Zahl ist durch 5 glatt teilbar
+
+
+
+
+
+
+
+
+
+
+
In [55]:
+
+
+
zahl=90.0
+isinstance(zahl,float)# Prüfen ob eine variable einem der Datentypen entspricht (hier float)
+
deff(x):# Einleiten einer Funktion
+''' Berechnet das quadrat einer Zahl'''# Docstring zum beschreiben der Funktion
+ # .... irgendeine Berechnung
+ rückgabewert=x*x# ist der rückgabewert
+ returnrückgabewert#
+
# Vereinigung aller heute gelernten Dinge außer der Funktions Definition
+
+# 99 Bootles of Beer
+beer=99
+whilebeer>-1:
+ print()
+ ifbeer==0:
+ print('''
+ No more bottles of beer on the wall, no more bottles of beer.
+ We've taken them down and passed them around;
+ now we're drunk and passed out!
+ ''')
+ elifbeer==1:
+ print(beer,"bottle of beer on the wall,",beer,"bottle of beer.")
+ print("Take one down and pass it around, no more bottles of beer on the wall.",end='')
+ else:
+ print(beer,"bottles of beer on the wall,",beer,"bottles of beer.")
+ ifbeer-1==1:
+ print(f"Take one down and pass it around, {beer-1} bottle of beer on the wall.")
+ else:
+ print(f"Take one down and pass it around, {beer-1} bottles of beer on the wall.")
+
+ beer-=1
+
+# Ausgabe ist zu groß für Slides
+
+
+
+
+
+
+
+
+
diff --git a/Material/2.vorlesung.ipynb b/Material/2.vorlesung.ipynb
index c83b1f9..fdb2070 100644
--- a/Material/2.vorlesung.ipynb
+++ b/Material/2.vorlesung.ipynb
@@ -3,24 +3,56 @@
{
"cell_type": "markdown",
"id": "53ef5460-e38f-4d51-92e3-7d680f23d710",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
"source": [
- "# Einführung in die Programmierung für Nicht Informatiker*innen"
+ "# 2. Einführung in die Programmierung für Nicht Informatiker*innen"
]
},
{
"cell_type": "markdown",
"id": "391a0811-2a99-4cde-8b88-bd7e0c1d6cb8",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"source": [
- "Survey: https://survey.cyperpunk.de/form/GVkRjB"
+ "Bitte ihre Jupyter Kennung + Vor- & Nachnamen unter folgendem link eintragen [survey](https://survey.cyperpunk.de/form/GVkRjB)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "c39f4116-a533-4d21-87e5-6d24268b995c",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
+ "source": [
+ "## Beispiele Print"
]
},
{
"cell_type": "code",
- "execution_count": 39,
+ "execution_count": 1,
"id": "48342195-b5a8-4298-9f83-2908c8a52821",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [
{
"name": "stdout",
@@ -34,14 +66,20 @@
"source": [
"# Beispiel Print\n",
"print(\"Hallo\", \"Python\", end='\\n') # Zeigen wie end Funktioniert\n",
- "print(\"Freitag 15h\")"
+ "print(\"Freitag 15h\") # Ausgabe mittels print"
]
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 2,
"id": "d08902d2-e454-4f81-bd63-30ef9a33deb2",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -49,20 +87,26 @@
"'Hallo Python'"
]
},
- "execution_count": 9,
+ "execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "\"Hallo Python\""
+ "\"Hallo Python\" # direkte ausgabe einer Variablen oder Wert"
]
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 3,
"id": "63ac2349-5a3d-49f5-b379-ec92ff502694",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -70,7 +114,7 @@
"432423654645"
]
},
- "execution_count": 10,
+ "execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
@@ -79,11 +123,31 @@
"432423654645 "
]
},
+ {
+ "cell_type": "markdown",
+ "id": "0b230834-0e94-48ff-9462-5b627726db70",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
+ "source": [
+ "## Variablen zuweisungen"
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": 4,
"id": "aa39464e-eaa1-4c8c-bd29-2ca20bc35336",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -91,21 +155,27 @@
"42"
]
},
- "execution_count": 12,
+ "execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "zahl1 = 42\n",
+ "zahl1 = 42 # 'zahl1' speichert den Wert '42'\n",
"zahl1"
]
},
{
"cell_type": "code",
- "execution_count": 13,
+ "execution_count": 5,
"id": "45281ff8-2c07-4774-9f96-e95a5b8f31ae",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [
{
"name": "stdout",
@@ -116,14 +186,20 @@
}
],
"source": [
- "print(zahl1)"
+ "print(zahl1) # Ausgabe der Variabeln mittels print"
]
},
{
"cell_type": "code",
- "execution_count": 14,
+ "execution_count": 6,
"id": "c9e3bf85-5b75-4efc-bbcc-9c5de28be421",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -131,7 +207,7 @@
"420"
]
},
- "execution_count": 14,
+ "execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
@@ -141,11 +217,31 @@
"zahl2"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "750a84cf-6528-4d1c-9e53-85da156d47a3",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
+ "source": [
+ "## Operationen mit Integern (gilt auch für Floats)"
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 15,
+ "execution_count": 7,
"id": "599a7dec-0e03-43a2-92df-a60777a33f03",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -153,25 +249,248 @@
"462"
]
},
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "zahl1 + zahl2 # Addition"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "id": "db143bf7-4d07-4a2b-b30a-b2f9054efeb6",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "-378"
+ ]
+ },
+ "execution_count": 8,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "zahl1 - zahl2 # Subtraction"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "id": "3b96f637-a5a2-4188-9632-a99faf881f76",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "378"
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "zahl2 - zahl1 # Order matters"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "id": "7dc56688-4dd5-441d-b9f1-2c17028338e6",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "17640"
+ ]
+ },
+ "execution_count": 10,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "zahl2 * zahl1 # Multiplikation"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "id": "4cb21e7e-f77d-4c5d-afb4-4aa0e7e974e5",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "10.0"
+ ]
+ },
+ "execution_count": 11,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "zahl2 / zahl1 # Division"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "id": "7d941f53-9fa4-494a-9871-bf02ecad97b7",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "16"
+ ]
+ },
+ "execution_count": 12,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "2**4 # Exponentiation"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "id": "0e6a2cae-c360-454c-a622-37e6fed45879",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "42.42"
+ ]
+ },
+ "execution_count": 13,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "float1 = 42.42 # Fließkommzahl speichern\n",
+ "float1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "id": "d360fc12-dfff-498e-95b8-664648fb8442",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "10"
+ ]
+ },
+ "execution_count": 14,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "zahl2 // zahl1 # Ganzzahldivision"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "id": "1813dd22-f4f0-499b-92aa-c5f5f95b8a6c",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "0"
+ ]
+ },
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "zahl1 + zahl2"
+ "42 % 2 # Modulo (Rest einer Division)"
]
},
{
"cell_type": "code",
"execution_count": 16,
- "id": "db143bf7-4d07-4a2b-b30a-b2f9054efeb6",
- "metadata": {},
+ "id": "87f97c26-4fa2-4192-ae5b-21a6adcb8aa4",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
"text/plain": [
- "-378"
+ "(21, 0)"
]
},
"execution_count": 16,
@@ -180,162 +499,20 @@
}
],
"source": [
- "zahl1 - zahl2"
+ "divmod(42, 2) # Kombinierte Built-in funktion, welche den Wert der Ganzzahldivision und den Rest berechnet"
]
},
{
"cell_type": "code",
"execution_count": 17,
- "id": "3b96f637-a5a2-4188-9632-a99faf881f76",
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "378"
- ]
- },
- "execution_count": 17,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "zahl2 - zahl1"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 18,
- "id": "7dc56688-4dd5-441d-b9f1-2c17028338e6",
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "17640"
- ]
- },
- "execution_count": 18,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "zahl2 * zahl1"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 19,
- "id": "4cb21e7e-f77d-4c5d-afb4-4aa0e7e974e5",
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "10.0"
- ]
- },
- "execution_count": 19,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "zahl2 / zahl1"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 21,
- "id": "0e6a2cae-c360-454c-a622-37e6fed45879",
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "42.42"
- ]
- },
- "execution_count": 21,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "float1 = 42.42\n",
- "float1"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 22,
- "id": "d360fc12-dfff-498e-95b8-664648fb8442",
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "10"
- ]
- },
- "execution_count": 22,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "zahl2 // zahl1"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 29,
- "id": "1813dd22-f4f0-499b-92aa-c5f5f95b8a6c",
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "0"
- ]
- },
- "execution_count": 29,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "42 % 2"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 30,
- "id": "87f97c26-4fa2-4192-ae5b-21a6adcb8aa4",
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "(21, 0)"
- ]
- },
- "execution_count": 30,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "divmod(42, 2)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 31,
"id": "5a8948ca-8662-43f1-9a1e-cb9bec803380",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -343,7 +520,7 @@
"21.0"
]
},
- "execution_count": 31,
+ "execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
@@ -354,9 +531,15 @@
},
{
"cell_type": "code",
- "execution_count": 32,
+ "execution_count": 18,
"id": "f17cc46a-906e-4fe9-9c0a-5cb81e09bcc5",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -364,7 +547,7 @@
"0"
]
},
- "execution_count": 32,
+ "execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
@@ -375,9 +558,15 @@
},
{
"cell_type": "code",
- "execution_count": 33,
+ "execution_count": 19,
"id": "a6d36974-b750-41e8-a0b3-a40fdba9f02c",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -385,20 +574,40 @@
"0.30000000000000004"
]
},
- "execution_count": 33,
+ "execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "0.1 + 0.2"
+ "0.1 + 0.2 # Addition von Floats sind nicht immer akkurat"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "73b246a0-f6d9-4e19-9dc3-a5e25efd0c8c",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
+ "source": [
+ "## Booleans"
]
},
{
"cell_type": "code",
- "execution_count": 34,
+ "execution_count": 20,
"id": "99e978bc-b40e-432a-81a0-801391760fb3",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -406,20 +615,26 @@
"False"
]
},
- "execution_count": 34,
+ "execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "0.1 + 0.2 == 0.3"
+ "0.1 + 0.2 == 0.3 # Nicht richtig aufgrund der unkorrekten binären darstellung von floats"
]
},
{
"cell_type": "code",
- "execution_count": 35,
+ "execution_count": 21,
"id": "fc761a8c-8988-4a20-81a1-28e33f11f138",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -427,20 +642,26 @@
"True"
]
},
- "execution_count": 35,
+ "execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "True"
+ "True "
]
},
{
"cell_type": "code",
- "execution_count": 36,
+ "execution_count": 22,
"id": "668ad1b3-741e-46fb-a3af-375861ecbd13",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -448,7 +669,7 @@
"False"
]
},
- "execution_count": 36,
+ "execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
@@ -459,9 +680,15 @@
},
{
"cell_type": "code",
- "execution_count": 37,
+ "execution_count": 23,
"id": "0b23648c-1a8a-44e9-9941-a5e0e8b80ffb",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -469,20 +696,40 @@
"2"
]
},
- "execution_count": 37,
+ "execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "True + True"
+ "True + True # Bools sind auch nur Zahlen (True = 1, False = 0)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "da342349-6c33-4fc6-864f-7171ac6dd029",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
+ "source": [
+ "## Listen"
]
},
{
"cell_type": "code",
- "execution_count": 45,
+ "execution_count": 24,
"id": "1b91f589-8469-49cf-90ba-af14d638d8eb",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -490,21 +737,27 @@
"['Hallo Python', 42, 10.1]"
]
},
- "execution_count": 45,
+ "execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "l = [\"Hallo Python\", 42, 10.10]\n",
+ "l = [\"Hallo Python\", 42, 10.10] # Erstellen einer Liste mit 3 elementen\n",
"l"
]
},
{
"cell_type": "code",
- "execution_count": 47,
+ "execution_count": 25,
"id": "678973b3-81ad-48e2-8ab2-c1784440a91c",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -512,21 +765,27 @@
"['Hallo Python', 42, 10.1, 'Text']"
]
},
- "execution_count": 47,
+ "execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "l.append(\"Text\")\n",
+ "l.append(\"Text\") # Weiteres Element an die liste anfügen\n",
"l"
]
},
{
"cell_type": "code",
- "execution_count": 48,
+ "execution_count": 26,
"id": "0c68eb51-c5f1-4650-9032-31f77a72006f",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -534,7 +793,7 @@
"['Hallo Python', 42, 10.1, 'Text']"
]
},
- "execution_count": 48,
+ "execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
@@ -545,9 +804,15 @@
},
{
"cell_type": "code",
- "execution_count": 49,
+ "execution_count": 27,
"id": "e41e1c08-b570-4423-a220-c428512ab686",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -555,21 +820,27 @@
"10.1"
]
},
- "execution_count": 49,
+ "execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "g = l[2]\n",
+ "g = l[2] # Zugriff auf das dritte Element der Liste\n",
"g"
]
},
{
"cell_type": "code",
- "execution_count": 50,
+ "execution_count": 28,
"id": "6a4dc400-c788-4105-a57d-c42a64bf8928",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -577,20 +848,26 @@
"'Hallo Python'"
]
},
- "execution_count": 50,
+ "execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "l[0]"
+ "l[0] # Zugriff erstes element der Liste"
]
},
{
"cell_type": "code",
- "execution_count": 52,
+ "execution_count": 29,
"id": "174211ad-dda8-4d43-87a1-eee4d582c47c",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -598,20 +875,26 @@
"42"
]
},
- "execution_count": 52,
+ "execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "l[-3]"
+ "l[-3] # Auff listen lässt sich auch 'rückwärts' zugreifen"
]
},
{
"cell_type": "code",
- "execution_count": 53,
+ "execution_count": 30,
"id": "8ed1b344-94d0-49d6-8662-ea81d33f9d8f",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -619,21 +902,41 @@
"['Hallo Python', 42, 10.1]"
]
},
- "execution_count": 53,
+ "execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "l.remove('Text')\n",
+ "l.remove('Text') # Einen Wert aus der Liste entfernen\n",
"l"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "5e1f1661-cb9d-464f-be4a-51d838bde23d",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
+ "source": [
+ "## Strings"
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 58,
+ "execution_count": 31,
"id": "a10e3b76-8b0c-4979-880c-cb5a86c1c42a",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -641,21 +944,27 @@
"'Tex\"t'"
]
},
- "execution_count": 58,
+ "execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "str1 = 'Tex\"t'\n",
+ "str1 = 'Tex\"t' # String mit ''\n",
"str1"
]
},
{
"cell_type": "code",
- "execution_count": 57,
+ "execution_count": 32,
"id": "783b1c13-fe63-452c-8f0e-8dab0c1173ee",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -663,21 +972,27 @@
"\"Text'2\""
]
},
- "execution_count": 57,
+ "execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "str2 = \"Text'2\"\n",
+ "str2 = \"Text'2\" # String mit \"\"\n",
"str2"
]
},
{
"cell_type": "code",
- "execution_count": 60,
+ "execution_count": 33,
"id": "91a8fb1e-c9ba-4e37-81d4-fae62e30fc8c",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -685,12 +1000,13 @@
"'\\nHallo dies ist ein \\necht langer \\nnicht formattierter \\ntext!!!! \\' \"\\n\\n'"
]
},
- "execution_count": 60,
+ "execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
+ "# Documentation Strings oder mehrzeillige Strings\n",
"str3 = '''\n",
"Hallo dies ist ein \n",
"echt langer \n",
@@ -698,14 +1014,20 @@
"text!!!! ' \"\n",
"\n",
"'''\n",
- "str3"
+ "str3 # Ausgabe mit escape Characters"
]
},
{
"cell_type": "code",
- "execution_count": 61,
+ "execution_count": 34,
"id": "7fa2bc58-3cf0-4ecb-ba6e-ab0af08c2806",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [
{
"name": "stdout",
@@ -722,14 +1044,20 @@
}
],
"source": [
- "print(str3)"
+ "print(str3) # \"Hübsche\" Ausgabe"
]
},
{
"cell_type": "code",
- "execution_count": 62,
+ "execution_count": 35,
"id": "430c663e-6320-45bb-85ac-3781394a4a37",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -737,20 +1065,26 @@
"'x'"
]
},
- "execution_count": 62,
+ "execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "str1[2]"
+ "str1[2] # Strings sind auch nur Listen"
]
},
{
"cell_type": "code",
- "execution_count": 63,
+ "execution_count": 36,
"id": "e2f20468-3ea7-411e-9c72-e29d5a344fa2",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -758,20 +1092,26 @@
"'Tex\"t ist ein text'"
]
},
- "execution_count": 63,
+ "execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "f\"{str1} ist ein text\""
+ "f\"{str1} ist ein text\" # F-String formatierung"
]
},
{
"cell_type": "code",
- "execution_count": 64,
+ "execution_count": 37,
"id": "58dc5f40-26df-45e8-9c36-319dce3a11cd",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -779,20 +1119,40 @@
"'Tex\"t ist ein text'"
]
},
- "execution_count": 64,
+ "execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "\"{} ist ein text\".format(str1)"
+ "\"{} ist ein text\".format(str1) # Formatierung mittels format funktion"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "8dc440b6-a8c3-43a5-937f-1748d6a23c41",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
+ "source": [
+ "## Tuples"
]
},
{
"cell_type": "code",
- "execution_count": 69,
+ "execution_count": 38,
"id": "cf0bd9a6-db63-4795-847f-b6dbd0cd4d1e",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -800,21 +1160,27 @@
"(42, 10.1)"
]
},
- "execution_count": 69,
+ "execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "tuple1 = (42, 10.10)\n",
+ "tuple1 = (42, 10.10) # Tuple erstellen\n",
"tuple1 "
]
},
{
"cell_type": "code",
- "execution_count": 70,
+ "execution_count": 39,
"id": "6a6c1c1e-ea17-4609-82c8-2fa02b05b208",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -822,20 +1188,26 @@
"42"
]
},
- "execution_count": 70,
+ "execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "tuple1[0]"
+ "tuple1[0] # auf element des Tupels zugreifen"
]
},
{
"cell_type": "code",
- "execution_count": 71,
+ "execution_count": 40,
"id": "a46ec0e4-0cb3-419b-ac9e-9f2a669812b0",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"ename": "AttributeError",
@@ -844,20 +1216,40 @@
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
- "Cell \u001b[0;32mIn[71], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mtuple1\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mappend\u001b[49m(\u001b[38;5;241m1\u001b[39m)\n",
+ "Cell \u001b[0;32mIn[40], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mtuple1\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mappend\u001b[49m(\u001b[38;5;241m1\u001b[39m) \u001b[38;5;66;03m# Tuples sind unveränderlich (immutable) daher können nicht einfach elemente angefügt werden\u001b[39;00m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'"
]
}
],
"source": [
- "tuple1.append(1)"
+ "tuple1.append(1) # Tuples sind unveränderlich (immutable) daher können nicht einfach elemente angefügt werden"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "448e1ab1-b51e-4577-a51d-da985079bb11",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
+ "source": [
+ "## Dictionarys"
]
},
{
"cell_type": "code",
- "execution_count": 72,
+ "execution_count": 41,
"id": "eb6815fd-755f-49e0-a9c3-71e28b1096c3",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -865,21 +1257,27 @@
"{'Name': 'Phil', 'Key': 42}"
]
},
- "execution_count": 72,
+ "execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "dict1 = {\"Name\": \"Phil\", \"Key\": 42}\n",
+ "dict1 = {\"Name\": \"Phil\", \"Key\": 42} # Dictionary erstellen\n",
"dict1"
]
},
{
"cell_type": "code",
- "execution_count": 74,
+ "execution_count": 42,
"id": "3a00b7f8-910b-4261-9b49-cee2fefab2ec",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -887,20 +1285,26 @@
"42"
]
},
- "execution_count": 74,
+ "execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "dict1[\"Key\"]"
+ "dict1[\"Key\"] # Zugriff auf element des Dicts mittels Schlüssel"
]
},
{
"cell_type": "code",
- "execution_count": 75,
+ "execution_count": 43,
"id": "9128089a-d000-4cb3-87e3-524a53a93b84",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -908,21 +1312,41 @@
"{'Name': 'Phil', 'Key': 42, 'Key2': 10}"
]
},
- "execution_count": 75,
+ "execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "dict1[\"Key2\"] = 10\n",
+ "dict1[\"Key2\"] = 10 # neues Element in das Dict einfügen\n",
"dict1"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "ea00b1d5-b0fa-4949-8d51-09b045f4d25b",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
+ "source": [
+ "## Sets"
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 76,
+ "execution_count": 44,
"id": "07a6f887-1831-42db-a81f-69ec41b6489b",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -930,21 +1354,41 @@
"{1, 2, 3, 4}"
]
},
- "execution_count": 76,
+ "execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "set1 = {1, 1, 2, 2, 3, 3, 4}\n",
- "set1"
+ "set1 = {1, 1, 2, 2, 3, 3, 4} # Set erstellen\n",
+ "set1 # Sets haben ausschließlich einzigartige Elemente "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "729cb47d-ae3c-4317-b19e-c423b1f1fc9a",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
+ "source": [
+ "## Conditionals"
]
},
{
"cell_type": "code",
- "execution_count": 77,
+ "execution_count": 45,
"id": "23dc654e-7434-4e41-8286-c9fa86aa2fae",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -952,20 +1396,26 @@
"True"
]
},
- "execution_count": 77,
+ "execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "42 % 2 == 0"
+ "42 % 2 == 0 # Prüfen auf equality"
]
},
{
"cell_type": "code",
- "execution_count": 82,
+ "execution_count": 46,
"id": "50757a7f-d3a2-43ba-9c59-f2b122661717",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"name": "stdout",
@@ -976,18 +1426,25 @@
}
],
"source": [
+ "# Unterschiedlichen Code ausführen je nach Bedingung\n",
"zahl = 32\n",
- "if zahl % 2 == 1:\n",
- " print(\"Ist Ungerade\")\n",
+ "if zahl % 2 == 1: # ist die zahl Gerade?\n",
+ " print(\"Ist Ungerade\") # Wenn Ja\n",
"else:\n",
- " print(\"Ist Gerade\")"
+ " print(\"Ist Gerade\") # Wenn Nein"
]
},
{
"cell_type": "code",
- "execution_count": 83,
+ "execution_count": 47,
"id": "645f5df9-8ade-4cf3-aa7f-6bf642d53674",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [
{
"name": "stdout",
@@ -998,29 +1455,42 @@
}
],
"source": [
+ "# Argument \"verneinen\"\n",
"zahl = 32\n",
- "if not zahl % 2 == 1:\n",
- " print(\"Ist Gerade\")\n",
+ "if not zahl % 2 == 1: # Ist die zahl nicht gerade?\n",
+ " print(\"Ist Gerade\") # Wenn Ja (Zahl nicht gerade -> Zahl gerade)\n",
"else:\n",
- " print(\"Ist Ungerade\")"
+ " print(\"Ist Ungerade\") # Wenn Nein "
]
},
{
"cell_type": "code",
- "execution_count": 85,
+ "execution_count": 48,
"id": "40d8928e-365b-4c73-a852-b13b507d7b2f",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [],
"source": [
- "if 42 % 2 == 0 and 36 % 2 == 1:\n",
+ "if 42 % 2 == 0 and 36 % 2 == 1: # Und verknüpfung alle bedingungen müssen wahr sein\n",
" print(\"Sind beide Gerade\")"
]
},
{
"cell_type": "code",
- "execution_count": 87,
+ "execution_count": 49,
"id": "082f72fe-8ced-4acd-bd51-0b7bec7195a7",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -1028,7 +1498,7 @@
"False"
]
},
- "execution_count": 87,
+ "execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
@@ -1039,9 +1509,15 @@
},
{
"cell_type": "code",
- "execution_count": 89,
+ "execution_count": 50,
"id": "0f911f39-056d-42bb-abfb-521fb926a1b1",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [
{
"name": "stdout",
@@ -1052,15 +1528,21 @@
}
],
"source": [
- "if 42 % 2 == 0 or 36 % 2 == 1:\n",
+ "if 42 % 2 == 0 or 36 % 2 == 1: # Oder Verknüpfung eine oder mehrere Bedingungen müssen wahr sein\n",
" print(\"Eine Zahl ist Gerade\")"
]
},
{
"cell_type": "code",
- "execution_count": 90,
+ "execution_count": 51,
"id": "e8b94c36-e921-455a-80ae-a9f6e38a6d57",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -1068,7 +1550,7 @@
"True"
]
},
- "execution_count": 90,
+ "execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
@@ -1079,9 +1561,15 @@
},
{
"cell_type": "code",
- "execution_count": 91,
+ "execution_count": 52,
"id": "e828d799-89af-4991-bdc7-39d70dd30614",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -1089,7 +1577,7 @@
"False"
]
},
- "execution_count": 91,
+ "execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
@@ -1100,9 +1588,15 @@
},
{
"cell_type": "code",
- "execution_count": 92,
+ "execution_count": 53,
"id": "db94bbb7-c422-4566-beea-d5d606825563",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -1110,7 +1604,7 @@
"True"
]
},
- "execution_count": 92,
+ "execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
@@ -1121,9 +1615,15 @@
},
{
"cell_type": "code",
- "execution_count": 97,
+ "execution_count": 54,
"id": "1a7093bc-a4ce-4fbd-97c0-f93570a185c7",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [
{
"name": "stdout",
@@ -1134,21 +1634,28 @@
}
],
"source": [
+ "# Verschiedene Bedingungen mit verschiedenen Ausgaben\n",
"zahl = 10\n",
"\n",
- "if zahl % 3 == 0:\n",
+ "if zahl % 3 == 0: # zahl durch 3 teilbar?\n",
" print(\"Zahl ist durch 3 glatt teilbar\")\n",
- "elif zahl % 5 == 0:\n",
+ "elif zahl % 5 == 0: # Zahl durch 5 teilbar?\n",
" print(\"Zahl ist durch 5 glatt teilbar\")\n",
- "else:\n",
+ "else: # Weder noch (Base Case)\n",
" print(\"Zahl ist nicht durch 3 oder 5 teilbar\")"
]
},
{
"cell_type": "code",
- "execution_count": 100,
+ "execution_count": 55,
"id": "eaa7e654-59b0-4ce4-80bf-f3ec83382663",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -1156,34 +1663,61 @@
"True"
]
},
- "execution_count": 100,
+ "execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zahl = 90.0\n",
- "isinstance(zahl, float)"
+ "isinstance(zahl, float) # Prüfen ob eine variable einem der Datentypen entspricht (hier float)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "dfb03801-ad4f-4006-837e-e6d62f36a02a",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
+ "source": [
+ "## Funktionen"
]
},
{
"cell_type": "code",
- "execution_count": 103,
+ "execution_count": 56,
"id": "e031a4f3-b42b-4a18-872c-1241a920b842",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
"outputs": [],
"source": [
- "def f(x):\n",
- " ''' Berechnet das quadrat einer Zahl'''\n",
+ "def f(x): # Einleiten einer Funktion\n",
+ " ''' Berechnet das quadrat einer Zahl''' # Docstring zum beschreiben der Funktion\n",
+ " # .... irgendeine Berechnung\n",
" rückgabewert = x*x # ist der rückgabewert\n",
- " return rückgabewert"
+ " return rückgabewert #"
]
},
{
"cell_type": "code",
- "execution_count": 104,
+ "execution_count": 57,
"id": "0f92364f-c666-485b-be38-d293cc167f17",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
"data": {
@@ -1191,7 +1725,7 @@
"49"
]
},
- "execution_count": 104,
+ "execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
@@ -1200,18 +1734,46 @@
"f(7)"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "173dd25d-f83c-4dc9-847b-8d4a6f9ba4b7",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
+ "source": [
+ "## While Loops"
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 110,
+ "execution_count": 58,
"id": "17722b1d-0491-451f-b130-01b89ee960cf",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "fragment"
+ },
+ "tags": []
+ },
"outputs": [
{
- "ename": "SyntaxError",
- "evalue": "invalid syntax (2373864270.py, line 1)",
- "output_type": "error",
- "traceback": [
- "\u001b[0;36m Cell \u001b[0;32mIn[110], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m i = # Condition\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "0 Hallo Python\n",
+ "1 Hallo Python\n",
+ "2 Hallo Python\n",
+ "3 Hallo Python\n",
+ "4 Hallo Python\n",
+ "5 Hallo Python\n",
+ "6 Hallo Python\n",
+ "7 Hallo Python\n",
+ "8 Hallo Python\n",
+ "9 Hallo Python\n"
]
}
],
@@ -1223,343 +1785,35 @@
]
},
{
- "cell_type": "code",
- "execution_count": 1,
- "id": "78d52a74-2213-4560-bbde-5a83bbe845e5",
- "metadata": {},
- "outputs": [
- {
- "ename": "AssertionError",
- "evalue": "",
- "output_type": "error",
- "traceback": [
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)",
- "Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(\u001b[38;5;241m42\u001b[39m, \u001b[38;5;28mfloat\u001b[39m)\n",
- "\u001b[0;31mAssertionError\u001b[0m: "
- ]
- }
- ],
+ "cell_type": "markdown",
+ "id": "974862d5-8279-4277-9008-726c45e392a3",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "slide"
+ },
+ "tags": []
+ },
"source": [
- "assert isinstance(42, float)"
+ "## 99 Bootles of Beer"
]
},
{
"cell_type": "code",
- "execution_count": 2,
- "id": "34aab3b4-c583-4027-b75d-0d0a6a948d40",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "\n",
- "99 bottles of beer on the wall, 99 bottles of beer.\n",
- "Take one down and pass it around, 98 bottles of beer on the wall.\n",
- "\n",
- "98 bottles of beer on the wall, 98 bottles of beer.\n",
- "Take one down and pass it around, 97 bottles of beer on the wall.\n",
- "\n",
- "97 bottles of beer on the wall, 97 bottles of beer.\n",
- "Take one down and pass it around, 96 bottles of beer on the wall.\n",
- "\n",
- "96 bottles of beer on the wall, 96 bottles of beer.\n",
- "Take one down and pass it around, 95 bottles of beer on the wall.\n",
- "\n",
- "95 bottles of beer on the wall, 95 bottles of beer.\n",
- "Take one down and pass it around, 94 bottles of beer on the wall.\n",
- "\n",
- "94 bottles of beer on the wall, 94 bottles of beer.\n",
- "Take one down and pass it around, 93 bottles of beer on the wall.\n",
- "\n",
- "93 bottles of beer on the wall, 93 bottles of beer.\n",
- "Take one down and pass it around, 92 bottles of beer on the wall.\n",
- "\n",
- "92 bottles of beer on the wall, 92 bottles of beer.\n",
- "Take one down and pass it around, 91 bottles of beer on the wall.\n",
- "\n",
- "91 bottles of beer on the wall, 91 bottles of beer.\n",
- "Take one down and pass it around, 90 bottles of beer on the wall.\n",
- "\n",
- "90 bottles of beer on the wall, 90 bottles of beer.\n",
- "Take one down and pass it around, 89 bottles of beer on the wall.\n",
- "\n",
- "89 bottles of beer on the wall, 89 bottles of beer.\n",
- "Take one down and pass it around, 88 bottles of beer on the wall.\n",
- "\n",
- "88 bottles of beer on the wall, 88 bottles of beer.\n",
- "Take one down and pass it around, 87 bottles of beer on the wall.\n",
- "\n",
- "87 bottles of beer on the wall, 87 bottles of beer.\n",
- "Take one down and pass it around, 86 bottles of beer on the wall.\n",
- "\n",
- "86 bottles of beer on the wall, 86 bottles of beer.\n",
- "Take one down and pass it around, 85 bottles of beer on the wall.\n",
- "\n",
- "85 bottles of beer on the wall, 85 bottles of beer.\n",
- "Take one down and pass it around, 84 bottles of beer on the wall.\n",
- "\n",
- "84 bottles of beer on the wall, 84 bottles of beer.\n",
- "Take one down and pass it around, 83 bottles of beer on the wall.\n",
- "\n",
- "83 bottles of beer on the wall, 83 bottles of beer.\n",
- "Take one down and pass it around, 82 bottles of beer on the wall.\n",
- "\n",
- "82 bottles of beer on the wall, 82 bottles of beer.\n",
- "Take one down and pass it around, 81 bottles of beer on the wall.\n",
- "\n",
- "81 bottles of beer on the wall, 81 bottles of beer.\n",
- "Take one down and pass it around, 80 bottles of beer on the wall.\n",
- "\n",
- "80 bottles of beer on the wall, 80 bottles of beer.\n",
- "Take one down and pass it around, 79 bottles of beer on the wall.\n",
- "\n",
- "79 bottles of beer on the wall, 79 bottles of beer.\n",
- "Take one down and pass it around, 78 bottles of beer on the wall.\n",
- "\n",
- "78 bottles of beer on the wall, 78 bottles of beer.\n",
- "Take one down and pass it around, 77 bottles of beer on the wall.\n",
- "\n",
- "77 bottles of beer on the wall, 77 bottles of beer.\n",
- "Take one down and pass it around, 76 bottles of beer on the wall.\n",
- "\n",
- "76 bottles of beer on the wall, 76 bottles of beer.\n",
- "Take one down and pass it around, 75 bottles of beer on the wall.\n",
- "\n",
- "75 bottles of beer on the wall, 75 bottles of beer.\n",
- "Take one down and pass it around, 74 bottles of beer on the wall.\n",
- "\n",
- "74 bottles of beer on the wall, 74 bottles of beer.\n",
- "Take one down and pass it around, 73 bottles of beer on the wall.\n",
- "\n",
- "73 bottles of beer on the wall, 73 bottles of beer.\n",
- "Take one down and pass it around, 72 bottles of beer on the wall.\n",
- "\n",
- "72 bottles of beer on the wall, 72 bottles of beer.\n",
- "Take one down and pass it around, 71 bottles of beer on the wall.\n",
- "\n",
- "71 bottles of beer on the wall, 71 bottles of beer.\n",
- "Take one down and pass it around, 70 bottles of beer on the wall.\n",
- "\n",
- "70 bottles of beer on the wall, 70 bottles of beer.\n",
- "Take one down and pass it around, 69 bottles of beer on the wall.\n",
- "\n",
- "69 bottles of beer on the wall, 69 bottles of beer.\n",
- "Take one down and pass it around, 68 bottles of beer on the wall.\n",
- "\n",
- "68 bottles of beer on the wall, 68 bottles of beer.\n",
- "Take one down and pass it around, 67 bottles of beer on the wall.\n",
- "\n",
- "67 bottles of beer on the wall, 67 bottles of beer.\n",
- "Take one down and pass it around, 66 bottles of beer on the wall.\n",
- "\n",
- "66 bottles of beer on the wall, 66 bottles of beer.\n",
- "Take one down and pass it around, 65 bottles of beer on the wall.\n",
- "\n",
- "65 bottles of beer on the wall, 65 bottles of beer.\n",
- "Take one down and pass it around, 64 bottles of beer on the wall.\n",
- "\n",
- "64 bottles of beer on the wall, 64 bottles of beer.\n",
- "Take one down and pass it around, 63 bottles of beer on the wall.\n",
- "\n",
- "63 bottles of beer on the wall, 63 bottles of beer.\n",
- "Take one down and pass it around, 62 bottles of beer on the wall.\n",
- "\n",
- "62 bottles of beer on the wall, 62 bottles of beer.\n",
- "Take one down and pass it around, 61 bottles of beer on the wall.\n",
- "\n",
- "61 bottles of beer on the wall, 61 bottles of beer.\n",
- "Take one down and pass it around, 60 bottles of beer on the wall.\n",
- "\n",
- "60 bottles of beer on the wall, 60 bottles of beer.\n",
- "Take one down and pass it around, 59 bottles of beer on the wall.\n",
- "\n",
- "59 bottles of beer on the wall, 59 bottles of beer.\n",
- "Take one down and pass it around, 58 bottles of beer on the wall.\n",
- "\n",
- "58 bottles of beer on the wall, 58 bottles of beer.\n",
- "Take one down and pass it around, 57 bottles of beer on the wall.\n",
- "\n",
- "57 bottles of beer on the wall, 57 bottles of beer.\n",
- "Take one down and pass it around, 56 bottles of beer on the wall.\n",
- "\n",
- "56 bottles of beer on the wall, 56 bottles of beer.\n",
- "Take one down and pass it around, 55 bottles of beer on the wall.\n",
- "\n",
- "55 bottles of beer on the wall, 55 bottles of beer.\n",
- "Take one down and pass it around, 54 bottles of beer on the wall.\n",
- "\n",
- "54 bottles of beer on the wall, 54 bottles of beer.\n",
- "Take one down and pass it around, 53 bottles of beer on the wall.\n",
- "\n",
- "53 bottles of beer on the wall, 53 bottles of beer.\n",
- "Take one down and pass it around, 52 bottles of beer on the wall.\n",
- "\n",
- "52 bottles of beer on the wall, 52 bottles of beer.\n",
- "Take one down and pass it around, 51 bottles of beer on the wall.\n",
- "\n",
- "51 bottles of beer on the wall, 51 bottles of beer.\n",
- "Take one down and pass it around, 50 bottles of beer on the wall.\n",
- "\n",
- "50 bottles of beer on the wall, 50 bottles of beer.\n",
- "Take one down and pass it around, 49 bottles of beer on the wall.\n",
- "\n",
- "49 bottles of beer on the wall, 49 bottles of beer.\n",
- "Take one down and pass it around, 48 bottles of beer on the wall.\n",
- "\n",
- "48 bottles of beer on the wall, 48 bottles of beer.\n",
- "Take one down and pass it around, 47 bottles of beer on the wall.\n",
- "\n",
- "47 bottles of beer on the wall, 47 bottles of beer.\n",
- "Take one down and pass it around, 46 bottles of beer on the wall.\n",
- "\n",
- "46 bottles of beer on the wall, 46 bottles of beer.\n",
- "Take one down and pass it around, 45 bottles of beer on the wall.\n",
- "\n",
- "45 bottles of beer on the wall, 45 bottles of beer.\n",
- "Take one down and pass it around, 44 bottles of beer on the wall.\n",
- "\n",
- "44 bottles of beer on the wall, 44 bottles of beer.\n",
- "Take one down and pass it around, 43 bottles of beer on the wall.\n",
- "\n",
- "43 bottles of beer on the wall, 43 bottles of beer.\n",
- "Take one down and pass it around, 42 bottles of beer on the wall.\n",
- "\n",
- "42 bottles of beer on the wall, 42 bottles of beer.\n",
- "Take one down and pass it around, 41 bottles of beer on the wall.\n",
- "\n",
- "41 bottles of beer on the wall, 41 bottles of beer.\n",
- "Take one down and pass it around, 40 bottles of beer on the wall.\n",
- "\n",
- "40 bottles of beer on the wall, 40 bottles of beer.\n",
- "Take one down and pass it around, 39 bottles of beer on the wall.\n",
- "\n",
- "39 bottles of beer on the wall, 39 bottles of beer.\n",
- "Take one down and pass it around, 38 bottles of beer on the wall.\n",
- "\n",
- "38 bottles of beer on the wall, 38 bottles of beer.\n",
- "Take one down and pass it around, 37 bottles of beer on the wall.\n",
- "\n",
- "37 bottles of beer on the wall, 37 bottles of beer.\n",
- "Take one down and pass it around, 36 bottles of beer on the wall.\n",
- "\n",
- "36 bottles of beer on the wall, 36 bottles of beer.\n",
- "Take one down and pass it around, 35 bottles of beer on the wall.\n",
- "\n",
- "35 bottles of beer on the wall, 35 bottles of beer.\n",
- "Take one down and pass it around, 34 bottles of beer on the wall.\n",
- "\n",
- "34 bottles of beer on the wall, 34 bottles of beer.\n",
- "Take one down and pass it around, 33 bottles of beer on the wall.\n",
- "\n",
- "33 bottles of beer on the wall, 33 bottles of beer.\n",
- "Take one down and pass it around, 32 bottles of beer on the wall.\n",
- "\n",
- "32 bottles of beer on the wall, 32 bottles of beer.\n",
- "Take one down and pass it around, 31 bottles of beer on the wall.\n",
- "\n",
- "31 bottles of beer on the wall, 31 bottles of beer.\n",
- "Take one down and pass it around, 30 bottles of beer on the wall.\n",
- "\n",
- "30 bottles of beer on the wall, 30 bottles of beer.\n",
- "Take one down and pass it around, 29 bottles of beer on the wall.\n",
- "\n",
- "29 bottles of beer on the wall, 29 bottles of beer.\n",
- "Take one down and pass it around, 28 bottles of beer on the wall.\n",
- "\n",
- "28 bottles of beer on the wall, 28 bottles of beer.\n",
- "Take one down and pass it around, 27 bottles of beer on the wall.\n",
- "\n",
- "27 bottles of beer on the wall, 27 bottles of beer.\n",
- "Take one down and pass it around, 26 bottles of beer on the wall.\n",
- "\n",
- "26 bottles of beer on the wall, 26 bottles of beer.\n",
- "Take one down and pass it around, 25 bottles of beer on the wall.\n",
- "\n",
- "25 bottles of beer on the wall, 25 bottles of beer.\n",
- "Take one down and pass it around, 24 bottles of beer on the wall.\n",
- "\n",
- "24 bottles of beer on the wall, 24 bottles of beer.\n",
- "Take one down and pass it around, 23 bottles of beer on the wall.\n",
- "\n",
- "23 bottles of beer on the wall, 23 bottles of beer.\n",
- "Take one down and pass it around, 22 bottles of beer on the wall.\n",
- "\n",
- "22 bottles of beer on the wall, 22 bottles of beer.\n",
- "Take one down and pass it around, 21 bottles of beer on the wall.\n",
- "\n",
- "21 bottles of beer on the wall, 21 bottles of beer.\n",
- "Take one down and pass it around, 20 bottles of beer on the wall.\n",
- "\n",
- "20 bottles of beer on the wall, 20 bottles of beer.\n",
- "Take one down and pass it around, 19 bottles of beer on the wall.\n",
- "\n",
- "19 bottles of beer on the wall, 19 bottles of beer.\n",
- "Take one down and pass it around, 18 bottles of beer on the wall.\n",
- "\n",
- "18 bottles of beer on the wall, 18 bottles of beer.\n",
- "Take one down and pass it around, 17 bottles of beer on the wall.\n",
- "\n",
- "17 bottles of beer on the wall, 17 bottles of beer.\n",
- "Take one down and pass it around, 16 bottles of beer on the wall.\n",
- "\n",
- "16 bottles of beer on the wall, 16 bottles of beer.\n",
- "Take one down and pass it around, 15 bottles of beer on the wall.\n",
- "\n",
- "15 bottles of beer on the wall, 15 bottles of beer.\n",
- "Take one down and pass it around, 14 bottles of beer on the wall.\n",
- "\n",
- "14 bottles of beer on the wall, 14 bottles of beer.\n",
- "Take one down and pass it around, 13 bottles of beer on the wall.\n",
- "\n",
- "13 bottles of beer on the wall, 13 bottles of beer.\n",
- "Take one down and pass it around, 12 bottles of beer on the wall.\n",
- "\n",
- "12 bottles of beer on the wall, 12 bottles of beer.\n",
- "Take one down and pass it around, 11 bottles of beer on the wall.\n",
- "\n",
- "11 bottles of beer on the wall, 11 bottles of beer.\n",
- "Take one down and pass it around, 10 bottles of beer on the wall.\n",
- "\n",
- "10 bottles of beer on the wall, 10 bottles of beer.\n",
- "Take one down and pass it around, 9 bottles of beer on the wall.\n",
- "\n",
- "9 bottles of beer on the wall, 9 bottles of beer.\n",
- "Take one down and pass it around, 8 bottles of beer on the wall.\n",
- "\n",
- "8 bottles of beer on the wall, 8 bottles of beer.\n",
- "Take one down and pass it around, 7 bottles of beer on the wall.\n",
- "\n",
- "7 bottles of beer on the wall, 7 bottles of beer.\n",
- "Take one down and pass it around, 6 bottles of beer on the wall.\n",
- "\n",
- "6 bottles of beer on the wall, 6 bottles of beer.\n",
- "Take one down and pass it around, 5 bottles of beer on the wall.\n",
- "\n",
- "5 bottles of beer on the wall, 5 bottles of beer.\n",
- "Take one down and pass it around, 4 bottles of beer on the wall.\n",
- "\n",
- "4 bottles of beer on the wall, 4 bottles of beer.\n",
- "Take one down and pass it around, 3 bottles of beer on the wall.\n",
- "\n",
- "3 bottles of beer on the wall, 3 bottles of beer.\n",
- "Take one down and pass it around, 2 bottles of beer on the wall.\n",
- "\n",
- "2 bottles of beer on the wall, 2 bottles of beer.\n",
- "Take one down and pass it around, 1 bottle of beer on the wall.\n",
- "\n",
- "1 bottle of beer on the wall, 1 bottle of beer.\n",
- "Take one down and pass it around, no more bottles of beer on the wall.\n",
- "\n",
- " No more bottles of beer on the wall, no more bottles of beer.\n",
- " We've taken them down and passed them around;\n",
- " now we're drunk and passed out!\n",
- " \n"
- ]
- }
- ],
+ "execution_count": null,
+ "id": "89075c38-1487-4175-8841-3546c8ac304f",
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": []
+ },
+ "outputs": [],
"source": [
+ "# Vereinigung aller heute gelernten Dinge außer der Funktions Definition\n",
+ "\n",
+ "# 99 Bootles of Beer \n",
"beer = 99\n",
"while beer > -1:\t\n",
" print()\n",
@@ -1579,16 +1833,10 @@
" else:\n",
" print(f\"Take one down and pass it around, {beer - 1} bottles of beer on the wall.\")\n",
" \n",
- " beer -= 1\n"
+ " beer -= 1\n",
+ "\n",
+ "# Ausgabe ist zu groß für Slides"
]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "0d7fbb11-ea09-4130-9263-6a8a3bfe14a9",
- "metadata": {},
- "outputs": [],
- "source": []
}
],
"metadata": {
@@ -1607,7 +1855,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.12.5"
+ "version": "3.12.7"
}
},
"nbformat": 4,
diff --git a/Material/2.vorlesung.slides.html b/Material/2.vorlesung.slides.html
new file mode 100644
index 0000000..1ceb7ad
--- /dev/null
+++ b/Material/2.vorlesung.slides.html
@@ -0,0 +1,9262 @@
+
+
+
+
+
+
+
+2.vorlesung slides
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2. Einführung in die Programmierung für Nicht Informatiker*innen¶
+
+
+
+
+
+
+
+
+
+
+
Bitte ihre Jupyter Kennung + Vor- & Nachnamen unter folgendem link eintragen survey
tuple1.append(1)# Tuples sind unveränderlich (immutable) daher können nicht einfach elemente angefügt werden
+
+
+
+
+
+
+
+
+
+
+
+
+
+---------------------------------------------------------------------------
+AttributeError Traceback (most recent call last)
+Cell In[40], line 1
+----> 1tuple1.append(1) # Tuples sind unveränderlich (immutable) daher können nicht einfach elemente angefügt werden
+
+AttributeError: 'tuple' object has no attribute 'append'
# Unterschiedlichen Code ausführen je nach Bedingung
+zahl=32
+ifzahl%2==1:# ist die zahl Gerade?
+ print("Ist Ungerade")# Wenn Ja
+else:
+ print("Ist Gerade")# Wenn Nein
+
+
+
+
+
+
+
+
+
+
+
+
+
Ist Gerade
+
+
+
+
+
+
+
+
+
+
+
In [47]:
+
+
+
# Argument "verneinen"
+zahl=32
+ifnotzahl%2==1:# Ist die zahl nicht gerade?
+ print("Ist Gerade")# Wenn Ja (Zahl nicht gerade -> Zahl gerade)
+else:
+ print("Ist Ungerade")# Wenn Nein
+
+
+
+
+
+
+
+
+
+
+
+
+
Ist Gerade
+
+
+
+
+
+
+
+
+
+
+
In [48]:
+
+
+
if42%2==0and36%2==1:# Und verknüpfung alle bedingungen müssen wahr sein
+ print("Sind beide Gerade")
+
+
+
+
+
+
+
+
+
+
+
In [49]:
+
+
+
TrueandFalse
+
+
+
+
+
+
+
+
+
+
+
Out[49]:
+
+
False
+
+
+
+
+
+
+
+
+
+
In [50]:
+
+
+
if42%2==0or36%2==1:# Oder Verknüpfung eine oder mehrere Bedingungen müssen wahr sein
+ print("Eine Zahl ist Gerade")
+
+
+
+
+
+
+
+
+
+
+
+
+
Eine Zahl ist Gerade
+
+
+
+
+
+
+
+
+
+
+
In [51]:
+
+
+
TrueorFalse
+
+
+
+
+
+
+
+
+
+
+
Out[51]:
+
+
True
+
+
+
+
+
+
+
+
+
+
In [52]:
+
+
+
FalseorFalse
+
+
+
+
+
+
+
+
+
+
+
Out[52]:
+
+
False
+
+
+
+
+
+
+
+
+
+
In [53]:
+
+
+
TrueorTrue
+
+
+
+
+
+
+
+
+
+
+
Out[53]:
+
+
True
+
+
+
+
+
+
+
+
+
+
In [54]:
+
+
+
# Verschiedene Bedingungen mit verschiedenen Ausgaben
+zahl=10
+
+ifzahl%3==0:# zahl durch 3 teilbar?
+ print("Zahl ist durch 3 glatt teilbar")
+elifzahl%5==0:# Zahl durch 5 teilbar?
+ print("Zahl ist durch 5 glatt teilbar")
+else:# Weder noch (Base Case)
+ print("Zahl ist nicht durch 3 oder 5 teilbar")
+
+
+
+
+
+
+
+
+
+
+
+
+
Zahl ist durch 5 glatt teilbar
+
+
+
+
+
+
+
+
+
+
+
In [55]:
+
+
+
zahl=90.0
+isinstance(zahl,float)# Prüfen ob eine variable einem der Datentypen entspricht (hier float)
+
deff(x):# Einleiten einer Funktion
+''' Berechnet das quadrat einer Zahl'''# Docstring zum beschreiben der Funktion
+ # .... irgendeine Berechnung
+ rückgabewert=x*x# ist der rückgabewert
+ returnrückgabewert#
+
# Vereinigung aller heute gelernten Dinge außer der Funktions Definition
+
+# 99 Bootles of Beer
+beer=99
+whilebeer>-1:
+ print()
+ ifbeer==0:
+ print('''
+ No more bottles of beer on the wall, no more bottles of beer.
+ We've taken them down and passed them around;
+ now we're drunk and passed out!
+ ''')
+ elifbeer==1:
+ print(beer,"bottle of beer on the wall,",beer,"bottle of beer.")
+ print("Take one down and pass it around, no more bottles of beer on the wall.",end='')
+ else:
+ print(beer,"bottles of beer on the wall,",beer,"bottles of beer.")
+ ifbeer-1==1:
+ print(f"Take one down and pass it around, {beer-1} bottle of beer on the wall.")
+ else:
+ print(f"Take one down and pass it around, {beer-1} bottles of beer on the wall.")
+
+ beer-=1
+
+# Ausgabe ist zu groß für Slides
+
Aufgabe: Geben Sie den Text Hallo Python aus. 1 Punkt
+
+
+
+
+
+
+
+
+
In [1]:
+
+
+
print("Hallo Python")
+
+
+
+
+
+
+
+
+
+
+
+
+
Hallo Python
+
+
+
+
+
+
+
+
+
+
+
+
+
Aufgabe2 Punkte:
+
Definieren Sie zunächst die zwei Variablen a und b und initialisieren diese mit einem Integerwert ungleich 0:
+
+
+
+
+
+
+
+
+
In [2]:
+
+
+
a=1
+b=-2
+
+
+
+
+
+
+
+
+
+
+
+
+
Aufgabe2 Punkte:
+
Definieren Sie zwei Variablen s und t und initialisieren diese mit einem Floatwert ungleich 0:
+
+
+
+
+
+
+
+
+
In [3]:
+
+
+
s=1.5
+t=-2.7
+
+
+
+
+
+
+
+
+
+
+
+
+
Aufgabe2 Punkte:
+
Addieren Sie die Werte der Variablen a und b und speichern Sie das Ergebnis in der Variable c:
+
+
+
+
+
+
+
+
+
In [4]:
+
+
+
c=a+b
+c
+
+
+
+
+
+
+
+
+
+
+
Out[4]:
+
+
-1
+
+
+
+
+
+
+
+
+
+
+
+
Aufgabe5 Punkte:
+
Nutzen Sie die Variablen a & b und Speichern Sie die Ergebnisse für die Multiplikation, Division, Ganzzahldivision, Exponentiation und den Modulo-Operator in den unten angegebenen Variablen:
Ein String-Objekt (Text) können sie mit Hilfe von 'Some Text' oder "Some Text2" definieren. Definieren sie die Variable text mit einem beliebigen Text.
+
+
+
+
+
+
+
+
+
In [6]:
+
+
+
text="Hi Mom, I am on TV!"
+print(text)
+
+
+
+
+
+
+
+
+
+
+
Out[6]:
+
+
'Hi Mom, I am on TV!'
+
+
+
+
+
+
+
+
+
+
+
+
Aufgabe1 Punkte:
+
Geben Sie die Variablen a & b aus Aufgabe 1 im format "a = 12 und b = 12" (Die Werte sollen dann den Werten aus ihrer Definition entsprechen. 12 ist hier nur ein Beispiel) aus.
+
+
+
+
+
+
+
+
+
In [7]:
+
+
+
# 1. Möglichkeit Format Funktion
+print("a = {} und b = {}".format(a,b))
+
+
+
+
+
+
+
+
+
+
+
+
+
a = 1 und b = -2
+
+
+
+
+
+
+
+
+
+
+
In [9]:
+
+
+
# 2. Möglichkeit 'f'-String
+print(f"a = {a} und b = {b}")
+
+
+
+
+
+
+
+
+
+
+
+
+
a = 1 und b = -2
+
+
+
+
+
+
+
+
+
+
+
+
+
Aufgabe1 Punkte:
+
Definieren Sie die Variable l und weisen Sie dieser Variable eine Liste mit aufsteigenden Integerwerten von 0 bis 4 zu.