2024-10-28 14:49:16 +01:00
{
"cells": [
{
"cell_type": "markdown",
"id": "53ef5460-e38f-4d51-92e3-7d680f23d710",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "slide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"source": [
2024-11-01 13:40:56 +01:00
"# 2. Einführung in die Programmierung für Nicht Informatiker*innen"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "markdown",
"id": "391a0811-2a99-4cde-8b88-bd7e0c1d6cb8",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"source": [
2024-11-01 13:40:56 +01:00
"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"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 1,
2024-10-28 14:49:16 +01:00
"id": "48342195-b5a8-4298-9f83-2908c8a52821",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hallo Python\n",
"Freitag 15h\n"
]
}
],
"source": [
"# Beispiel Print\n",
"print(\"Hallo\", \"Python\", end='\\n') # Zeigen wie end Funktioniert\n",
2024-11-01 13:40:56 +01:00
"print(\"Freitag 15h\") # Ausgabe mittels print"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 2,
2024-10-28 14:49:16 +01:00
"id": "d08902d2-e454-4f81-bd63-30ef9a33deb2",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"'Hallo Python'"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 2,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"\"Hallo Python\" # direkte ausgabe einer Variablen oder Wert"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 3,
2024-10-28 14:49:16 +01:00
"id": "63ac2349-5a3d-49f5-b379-ec92ff502694",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"432423654645"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 3,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"432423654645 "
]
},
2024-11-01 13:40:56 +01:00
{
"cell_type": "markdown",
"id": "0b230834-0e94-48ff-9462-5b627726db70",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "slide"
},
"tags": []
},
"source": [
"## Variablen zuweisungen"
]
},
2024-10-28 14:49:16 +01:00
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 4,
2024-10-28 14:49:16 +01:00
"id": "aa39464e-eaa1-4c8c-bd29-2ca20bc35336",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"42"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 4,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"zahl1 = 42 # 'zahl1' speichert den Wert '42'\n",
2024-10-28 14:49:16 +01:00
"zahl1"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 5,
2024-10-28 14:49:16 +01:00
"id": "45281ff8-2c07-4774-9f96-e95a5b8f31ae",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"42\n"
]
}
],
"source": [
2024-11-01 13:40:56 +01:00
"print(zahl1) # Ausgabe der Variabeln mittels print"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 6,
2024-10-28 14:49:16 +01:00
"id": "c9e3bf85-5b75-4efc-bbcc-9c5de28be421",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"420"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 6,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zahl2 = 420\n",
"zahl2"
]
},
2024-11-01 13:40:56 +01:00
{
"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)"
]
},
2024-10-28 14:49:16 +01:00
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 7,
2024-10-28 14:49:16 +01:00
"id": "599a7dec-0e03-43a2-92df-a60777a33f03",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"462"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 7,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"zahl1 + zahl2 # Addition"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 8,
2024-10-28 14:49:16 +01:00
"id": "db143bf7-4d07-4a2b-b30a-b2f9054efeb6",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"-378"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 8,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"zahl1 - zahl2 # Subtraction"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 9,
2024-10-28 14:49:16 +01:00
"id": "3b96f637-a5a2-4188-9632-a99faf881f76",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"378"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 9,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"zahl2 - zahl1 # Order matters"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 10,
2024-10-28 14:49:16 +01:00
"id": "7dc56688-4dd5-441d-b9f1-2c17028338e6",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"17640"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 10,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"zahl2 * zahl1 # Multiplikation"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 11,
2024-10-28 14:49:16 +01:00
"id": "4cb21e7e-f77d-4c5d-afb4-4aa0e7e974e5",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"10.0"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 11,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"zahl2 / zahl1 # Division"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"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,
2024-10-28 14:49:16 +01:00
"id": "0e6a2cae-c360-454c-a622-37e6fed45879",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"42.42"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 13,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"float1 = 42.42 # Fließkommzahl speichern\n",
2024-10-28 14:49:16 +01:00
"float1"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 14,
2024-10-28 14:49:16 +01:00
"id": "d360fc12-dfff-498e-95b8-664648fb8442",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 14,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"zahl2 // zahl1 # Ganzzahldivision"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 15,
2024-10-28 14:49:16 +01:00
"id": "1813dd22-f4f0-499b-92aa-c5f5f95b8a6c",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 15,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"42 % 2 # Modulo (Rest einer Division)"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 16,
2024-10-28 14:49:16 +01:00
"id": "87f97c26-4fa2-4192-ae5b-21a6adcb8aa4",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"(21, 0)"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 16,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"divmod(42, 2) # Kombinierte Built-in funktion, welche den Wert der Ganzzahldivision und den Rest berechnet"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 17,
2024-10-28 14:49:16 +01:00
"id": "5a8948ca-8662-43f1-9a1e-cb9bec803380",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"21.0"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 17,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"42 / 2"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 18,
2024-10-28 14:49:16 +01:00
"id": "f17cc46a-906e-4fe9-9c0a-5cb81e09bcc5",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 18,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"42 % 2"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 19,
2024-10-28 14:49:16 +01:00
"id": "a6d36974-b750-41e8-a0b3-a40fdba9f02c",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"0.30000000000000004"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 19,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"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"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 20,
2024-10-28 14:49:16 +01:00
"id": "99e978bc-b40e-432a-81a0-801391760fb3",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 20,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"0.1 + 0.2 == 0.3 # Nicht richtig aufgrund der unkorrekten binären darstellung von floats"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 21,
2024-10-28 14:49:16 +01:00
"id": "fc761a8c-8988-4a20-81a1-28e33f11f138",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 21,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"True "
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 22,
2024-10-28 14:49:16 +01:00
"id": "668ad1b3-741e-46fb-a3af-375861ecbd13",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 22,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 23,
2024-10-28 14:49:16 +01:00
"id": "0b23648c-1a8a-44e9-9941-a5e0e8b80ffb",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 23,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"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"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 24,
2024-10-28 14:49:16 +01:00
"id": "1b91f589-8469-49cf-90ba-af14d638d8eb",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"['Hallo Python', 42, 10.1]"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 24,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"l = [\"Hallo Python\", 42, 10.10] # Erstellen einer Liste mit 3 elementen\n",
2024-10-28 14:49:16 +01:00
"l"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 25,
2024-10-28 14:49:16 +01:00
"id": "678973b3-81ad-48e2-8ab2-c1784440a91c",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"['Hallo Python', 42, 10.1, 'Text']"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 25,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"l.append(\"Text\") # Weiteres Element an die liste anfügen\n",
2024-10-28 14:49:16 +01:00
"l"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 26,
2024-10-28 14:49:16 +01:00
"id": "0c68eb51-c5f1-4650-9032-31f77a72006f",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"['Hallo Python', 42, 10.1, 'Text']"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 26,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"l"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 27,
2024-10-28 14:49:16 +01:00
"id": "e41e1c08-b570-4423-a220-c428512ab686",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"10.1"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 27,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"g = l[2] # Zugriff auf das dritte Element der Liste\n",
2024-10-28 14:49:16 +01:00
"g"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 28,
2024-10-28 14:49:16 +01:00
"id": "6a4dc400-c788-4105-a57d-c42a64bf8928",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"'Hallo Python'"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 28,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"l[0] # Zugriff erstes element der Liste"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 29,
2024-10-28 14:49:16 +01:00
"id": "174211ad-dda8-4d43-87a1-eee4d582c47c",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"42"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 29,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"l[-3] # Auff listen lässt sich auch 'rückwärts' zugreifen"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 30,
2024-10-28 14:49:16 +01:00
"id": "8ed1b344-94d0-49d6-8662-ea81d33f9d8f",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"['Hallo Python', 42, 10.1]"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 30,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"l.remove('Text') # Einen Wert aus der Liste entfernen\n",
2024-10-28 14:49:16 +01:00
"l"
]
},
2024-11-01 13:40:56 +01:00
{
"cell_type": "markdown",
"id": "5e1f1661-cb9d-464f-be4a-51d838bde23d",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "slide"
},
"tags": []
},
"source": [
"## Strings"
]
},
2024-10-28 14:49:16 +01:00
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 31,
2024-10-28 14:49:16 +01:00
"id": "a10e3b76-8b0c-4979-880c-cb5a86c1c42a",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"'Tex\"t'"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 31,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"str1 = 'Tex\"t' # String mit ''\n",
2024-10-28 14:49:16 +01:00
"str1"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 32,
2024-10-28 14:49:16 +01:00
"id": "783b1c13-fe63-452c-8f0e-8dab0c1173ee",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"\"Text'2\""
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 32,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"str2 = \"Text'2\" # String mit \"\"\n",
2024-10-28 14:49:16 +01:00
"str2"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 33,
2024-10-28 14:49:16 +01:00
"id": "91a8fb1e-c9ba-4e37-81d4-fae62e30fc8c",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"'\\nHallo dies ist ein \\necht langer \\nnicht formattierter \\ntext!!!! \\' \"\\n\\n'"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 33,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"# Documentation Strings oder mehrzeillige Strings\n",
2024-10-28 14:49:16 +01:00
"str3 = '''\n",
"Hallo dies ist ein \n",
"echt langer \n",
"nicht formattierter \n",
"text!!!! ' \"\n",
"\n",
"'''\n",
2024-11-01 13:40:56 +01:00
"str3 # Ausgabe mit escape Characters"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 34,
2024-10-28 14:49:16 +01:00
"id": "7fa2bc58-3cf0-4ecb-ba6e-ab0af08c2806",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Hallo dies ist ein \n",
"echt langer \n",
"nicht formattierter \n",
"text!!!! ' \"\n",
"\n",
"\n"
]
}
],
"source": [
2024-11-01 13:40:56 +01:00
"print(str3) # \"Hübsche\" Ausgabe"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 35,
2024-10-28 14:49:16 +01:00
"id": "430c663e-6320-45bb-85ac-3781394a4a37",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"'x'"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 35,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"str1[2] # Strings sind auch nur Listen"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 36,
2024-10-28 14:49:16 +01:00
"id": "e2f20468-3ea7-411e-9c72-e29d5a344fa2",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"'Tex\"t ist ein text'"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 36,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"f\"{str1} ist ein text\" # F-String formatierung"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 37,
2024-10-28 14:49:16 +01:00
"id": "58dc5f40-26df-45e8-9c36-319dce3a11cd",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"'Tex\"t ist ein text'"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 37,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"\"{} 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"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 38,
2024-10-28 14:49:16 +01:00
"id": "cf0bd9a6-db63-4795-847f-b6dbd0cd4d1e",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"(42, 10.1)"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 38,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"tuple1 = (42, 10.10) # Tuple erstellen\n",
2024-10-28 14:49:16 +01:00
"tuple1 "
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 39,
2024-10-28 14:49:16 +01:00
"id": "6a6c1c1e-ea17-4609-82c8-2fa02b05b208",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"42"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 39,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"tuple1[0] # auf element des Tupels zugreifen"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 40,
2024-10-28 14:49:16 +01:00
"id": "a46ec0e4-0cb3-419b-ac9e-9f2a669812b0",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"ename": "AttributeError",
"evalue": "'tuple' object has no attribute 'append'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
2024-11-01 13:40:56 +01:00
"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",
2024-10-28 14:49:16 +01:00
"\u001b[0;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'"
]
}
],
"source": [
2024-11-01 13:40:56 +01:00
"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"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 41,
2024-10-28 14:49:16 +01:00
"id": "eb6815fd-755f-49e0-a9c3-71e28b1096c3",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"{'Name': 'Phil', 'Key': 42}"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 41,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"dict1 = {\"Name\": \"Phil\", \"Key\": 42} # Dictionary erstellen\n",
2024-10-28 14:49:16 +01:00
"dict1"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 42,
2024-10-28 14:49:16 +01:00
"id": "3a00b7f8-910b-4261-9b49-cee2fefab2ec",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"42"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 42,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"dict1[\"Key\"] # Zugriff auf element des Dicts mittels Schlüssel"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 43,
2024-10-28 14:49:16 +01:00
"id": "9128089a-d000-4cb3-87e3-524a53a93b84",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"{'Name': 'Phil', 'Key': 42, 'Key2': 10}"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 43,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"dict1[\"Key2\"] = 10 # neues Element in das Dict einfügen\n",
2024-10-28 14:49:16 +01:00
"dict1"
]
},
2024-11-01 13:40:56 +01:00
{
"cell_type": "markdown",
"id": "ea00b1d5-b0fa-4949-8d51-09b045f4d25b",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "slide"
},
"tags": []
},
"source": [
"## Sets"
]
},
2024-10-28 14:49:16 +01:00
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 44,
2024-10-28 14:49:16 +01:00
"id": "07a6f887-1831-42db-a81f-69ec41b6489b",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"{1, 2, 3, 4}"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 44,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"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"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 45,
2024-10-28 14:49:16 +01:00
"id": "23dc654e-7434-4e41-8286-c9fa86aa2fae",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 45,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-11-01 13:40:56 +01:00
"42 % 2 == 0 # Prüfen auf equality"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 46,
2024-10-28 14:49:16 +01:00
"id": "50757a7f-d3a2-43ba-9c59-f2b122661717",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ist Gerade\n"
]
}
],
"source": [
2024-11-01 13:40:56 +01:00
"# Unterschiedlichen Code ausführen je nach Bedingung\n",
2024-10-28 14:49:16 +01:00
"zahl = 32\n",
2024-11-01 13:40:56 +01:00
"if zahl % 2 == 1: # ist die zahl Gerade?\n",
" print(\"Ist Ungerade\") # Wenn Ja\n",
2024-10-28 14:49:16 +01:00
"else:\n",
2024-11-01 13:40:56 +01:00
" print(\"Ist Gerade\") # Wenn Nein"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 47,
2024-10-28 14:49:16 +01:00
"id": "645f5df9-8ade-4cf3-aa7f-6bf642d53674",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ist Gerade\n"
]
}
],
"source": [
2024-11-01 13:40:56 +01:00
"# Argument \"verneinen\"\n",
2024-10-28 14:49:16 +01:00
"zahl = 32\n",
2024-11-01 13:40:56 +01:00
"if not zahl % 2 == 1: # Ist die zahl nicht gerade?\n",
" print(\"Ist Gerade\") # Wenn Ja (Zahl nicht gerade -> Zahl gerade)\n",
2024-10-28 14:49:16 +01:00
"else:\n",
2024-11-01 13:40:56 +01:00
" print(\"Ist Ungerade\") # Wenn Nein "
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 48,
2024-10-28 14:49:16 +01:00
"id": "40d8928e-365b-4c73-a852-b13b507d7b2f",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [],
"source": [
2024-11-01 13:40:56 +01:00
"if 42 % 2 == 0 and 36 % 2 == 1: # Und verknüpfung alle bedingungen müssen wahr sein\n",
2024-10-28 14:49:16 +01:00
" print(\"Sind beide Gerade\")"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 49,
2024-10-28 14:49:16 +01:00
"id": "082f72fe-8ced-4acd-bd51-0b7bec7195a7",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 49,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True and False"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 50,
2024-10-28 14:49:16 +01:00
"id": "0f911f39-056d-42bb-abfb-521fb926a1b1",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Eine Zahl ist Gerade\n"
]
}
],
"source": [
2024-11-01 13:40:56 +01:00
"if 42 % 2 == 0 or 36 % 2 == 1: # Oder Verknüpfung eine oder mehrere Bedingungen müssen wahr sein\n",
2024-10-28 14:49:16 +01:00
" print(\"Eine Zahl ist Gerade\")"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 51,
2024-10-28 14:49:16 +01:00
"id": "e8b94c36-e921-455a-80ae-a9f6e38a6d57",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 51,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True or False"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 52,
2024-10-28 14:49:16 +01:00
"id": "e828d799-89af-4991-bdc7-39d70dd30614",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 52,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False or False"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 53,
2024-10-28 14:49:16 +01:00
"id": "db94bbb7-c422-4566-beea-d5d606825563",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 53,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True or True"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 54,
2024-10-28 14:49:16 +01:00
"id": "1a7093bc-a4ce-4fbd-97c0-f93570a185c7",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Zahl ist durch 5 glatt teilbar\n"
]
}
],
"source": [
2024-11-01 13:40:56 +01:00
"# Verschiedene Bedingungen mit verschiedenen Ausgaben\n",
2024-10-28 14:49:16 +01:00
"zahl = 10\n",
"\n",
2024-11-01 13:40:56 +01:00
"if zahl % 3 == 0: # zahl durch 3 teilbar?\n",
2024-10-28 14:49:16 +01:00
" print(\"Zahl ist durch 3 glatt teilbar\")\n",
2024-11-01 13:40:56 +01:00
"elif zahl % 5 == 0: # Zahl durch 5 teilbar?\n",
2024-10-28 14:49:16 +01:00
" print(\"Zahl ist durch 5 glatt teilbar\")\n",
2024-11-01 13:40:56 +01:00
"else: # Weder noch (Base Case)\n",
2024-10-28 14:49:16 +01:00
" print(\"Zahl ist nicht durch 3 oder 5 teilbar\")"
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 55,
2024-10-28 14:49:16 +01:00
"id": "eaa7e654-59b0-4ce4-80bf-f3ec83382663",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 55,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zahl = 90.0\n",
2024-11-01 13:40:56 +01:00
"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"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 56,
2024-10-28 14:49:16 +01:00
"id": "e031a4f3-b42b-4a18-872c-1241a920b842",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [],
"source": [
2024-11-01 13:40:56 +01:00
"def f(x): # Einleiten einer Funktion\n",
" ''' Berechnet das quadrat einer Zahl''' # Docstring zum beschreiben der Funktion\n",
" # .... irgendeine Berechnung\n",
2024-10-28 14:49:16 +01:00
" rückgabewert = x*x # ist der rückgabewert\n",
2024-11-01 13:40:56 +01:00
" return rückgabewert #"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 57,
2024-10-28 14:49:16 +01:00
"id": "0f92364f-c666-485b-be38-d293cc167f17",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
"data": {
"text/plain": [
"49"
]
},
2024-11-01 13:40:56 +01:00
"execution_count": 57,
2024-10-28 14:49:16 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f(7)"
]
},
2024-11-01 13:40:56 +01:00
{
"cell_type": "markdown",
"id": "173dd25d-f83c-4dc9-847b-8d4a6f9ba4b7",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "slide"
},
"tags": []
},
"source": [
"## While Loops"
]
},
2024-10-28 14:49:16 +01:00
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": 58,
2024-10-28 14:49:16 +01:00
"id": "17722b1d-0491-451f-b130-01b89ee960cf",
2024-11-01 13:40:56 +01:00
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "fragment"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"outputs": [
{
2024-11-01 13:40:56 +01:00
"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"
2024-10-28 14:49:16 +01:00
]
}
],
"source": [
"i = 0 # Condition\n",
"while i < 10: # Prüfung\n",
" print(i, \"Hallo Python\")\n",
" i = i + 1 # Anpassung"
]
},
{
2024-11-01 13:40:56 +01:00
"cell_type": "markdown",
"id": "974862d5-8279-4277-9008-726c45e392a3",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "slide"
},
"tags": []
},
2024-10-28 14:49:16 +01:00
"source": [
2024-11-01 13:40:56 +01:00
"## 99 Bootles of Beer"
2024-10-28 14:49:16 +01:00
]
},
{
"cell_type": "code",
2024-11-01 13:40:56 +01:00
"execution_count": null,
"id": "89075c38-1487-4175-8841-3546c8ac304f",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
},
"tags": []
},
"outputs": [],
2024-10-28 14:49:16 +01:00
"source": [
2024-11-01 13:40:56 +01:00
"# Vereinigung aller heute gelernten Dinge außer der Funktions Definition\n",
"\n",
"# 99 Bootles of Beer \n",
2024-10-28 14:49:16 +01:00
"beer = 99\n",
"while beer > -1:\t\n",
" print()\n",
" if beer == 0:\n",
" print('''\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",
" elif beer == 1:\n",
" print(beer, \"bottle of beer on the wall,\", beer, \"bottle of beer.\")\n",
" print(\"Take one down and pass it around, no more bottles of beer on the wall.\", end='')\n",
" else:\n",
" print(beer, \"bottles of beer on the wall,\", beer, \"bottles of beer.\")\n",
" if beer - 1 == 1:\n",
" print(f\"Take one down and pass it around, {beer - 1} bottle of beer on the wall.\") \n",
" else:\n",
" print(f\"Take one down and pass it around, {beer - 1} bottles of beer on the wall.\")\n",
" \n",
2024-11-01 13:40:56 +01:00
" beer -= 1\n",
"\n",
"# Ausgabe ist zu groß für Slides"
2024-10-28 14:49:16 +01:00
]
}
],
"metadata": {
"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",
2024-11-01 13:40:56 +01:00
"version": "3.12.7"
2024-10-28 14:49:16 +01:00
}
},
"nbformat": 4,
"nbformat_minor": 5
}