sq_01_python_intro/jupyter_book/01_taschenrechner.ipynb

276 lines
5.4 KiB
Plaintext
Raw Permalink Normal View History

{
"cells": [
{
"cell_type": "markdown",
"id": "1a44722c-9586-4418-ad7f-8a3c964a9db8",
"metadata": {},
"source": [
"# Taschenrechner\n",
"Wir fangen ganz einfach an und schauen, wie sich Python als Taschenrechner macht:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "1e6aecc1-1fbc-4cd9-9330-1a66fa612ec6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "f19f790e-bac5-4e31-a205-d2008bfc6e22",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"24"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 * 3 * 4"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "82d3380b-1d01-4475-8222-2198d8d4856a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"43"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 3 * 14"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "62b5e2b5-2bb5-42c3-b80e-8f43347faf5f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"56"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(1+3) * 14"
]
},
{
"cell_type": "markdown",
"id": "98a86261-0a33-4570-9064-ad57765e8aa0",
"metadata": {},
"source": [
"## Aufgabe\n",
"❓ Jetzt seid ihr dran! Denkt an den Mathe-Unterricht zurück und versucht\n",
"* Minus\n",
"* Division\n",
"* Potenzieren\n",
"* Quadratwurzel"
]
},
{
"cell_type": "markdown",
"id": "e2b5f4f4-a5da-4b70-9e11-1a13c8b1c111",
"metadata": {},
"source": [
"## Lösung"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "6d6e56ec-fded-4a99-8941-e88c323eb561",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5 - 2"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a151e074-017d-4be4-be9e-0181dca4cd9e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.5"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5 / 2"
]
},
{
"cell_type": "markdown",
"id": "e2ba9ae6-a19e-449a-a1d3-06be54dff4b3",
"metadata": {},
"source": [
"Kommazahlen gibt's auch. Diese müssen, wie im Englischen üblich, mit Punkt statt mit Komma angegeben werden."
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "b26ab8eb-cbf6-486e-a0a2-dfa086125742",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"64"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 ** 6"
]
},
{
"cell_type": "markdown",
"id": "5e7be5dd-bbcf-4f68-9cfb-662ac00f86c9",
"metadata": {},
"source": [
"Potenzieren war schon tricky. Die ** kann man sich aber einfach merken wenn man daran denkt das Potenzieren mehrfaches Multiplizieren ist.\n",
"\n",
"Für die Quadratwurzel müssen wir aber noch ein bisschen über Python lernen."
]
},
{
"cell_type": "markdown",
"id": "cec7a8a1-ce22-41a0-b0e2-b6107e9b9bc3",
"metadata": {},
"source": [
"# Packages\n",
"\n",
"Der Kern der Programmiersprache Python kann relativ wenig. Die meiste Funktionalität liegt in Packages.\n",
"\n",
"So ein Package muss mittels `import` verfügbar gemacht werden bevor man dessen Funktionen nutzen kann."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "c04b1fca-a1f5-4ba2-90a8-216c3cc41556",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.0"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import math\n",
"math.sqrt(4)"
]
},
{
"cell_type": "markdown",
"id": "dd7f5220-4b6d-4e76-8cdf-ed04b9d8e8d6",
"metadata": {},
"source": [
"## Aufgabe\n",
"❓ Das Package `math` enhält noch eine Reihe weiterer\n",
"Funktionen, die aus dem Mathe-Unterricht bekannt sind. Welche sind das?"
]
},
{
"cell_type": "markdown",
"id": "9b1cbddd-4599-4dbd-b439-5276c78e0ccd",
"metadata": {},
"source": [
"## Lösung\n",
"Durch ausprobieren kann man `sin`, `cos` und `tan` finden.\n",
"\n",
"Das ist aber aufwändig. Einfacher geht's mit der Hilfe-Funktion."
]
}
],
"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",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}