Skip to content

Weitere Aufgabe für Übung Operatoren #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 129 additions & 1 deletion book/content/Exercises/02_python/02_operationen/operationen.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"tags": [
Expand All @@ -24,20 +25,23 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Operationen"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Operationen sind die Grundstruktur eines Python-Programms. In dieser Aufgabe werden die vorgestellten Operationen vertieft."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"tags": [
Expand All @@ -49,13 +53,15 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Aufgabenteil A"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -70,6 +76,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"tags": [
Expand Down Expand Up @@ -216,13 +223,15 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Aufgabenteil B"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -235,6 +244,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"tags": [
Expand All @@ -247,6 +257,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"tags": [
Expand Down Expand Up @@ -284,6 +295,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"tags": [
Expand Down Expand Up @@ -312,6 +324,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"tags": [
Expand Down Expand Up @@ -348,6 +361,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"tags": [
Expand Down Expand Up @@ -377,6 +391,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -386,6 +401,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"tags": [
Expand Down Expand Up @@ -440,6 +456,118 @@
"print(\"Das Abstandsquadrat ist: \", dist2)\n",
"print(\"Die Koordinaten des Mittelpunkts sind: (\", mx, \",\", my, \")\")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Aufgabenteil D\n",
"Speicherverbrauch und Performance ist bei komplexen Algorithmen ein wichtiges Thema und müssen auf den jeweiligen Fall angepasst werden. Eine Optimierung wäre z.B. statt einer Liste von Booleans eine Zahl zu verwenden, bei der jeder Bit als Wahr oder Falsch interpretiert werden kann.\n",
"\n",
"Überprüfen sie ob ...\n",
"1. ... mindestens ein Bit von `10100101` wahr ist.\n",
"2. ... alle Bits von `10100101` falsch sind.\n",
"3. ... mindestens ein Bit von `10100101` falsch ist\n",
"4. ... alle Bits von `10100101` wahr sind.\n",
"\n",
"Wie würde ein Programm aussehen, bei dem die einzeln Bits als `True` und `False` ausgeschrieben werden?"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Lösungshinweis\n",
"Um eine Zahl im Binärsystem zu definieren wird das Präfix `0b` verwendet."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"'10100101' im Dezimalsystem: 165\n"
]
}
],
"source": [
"print(\"'10100101' im Dezimalsystem:\", 0b10100101)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"tags": [
"loesung",
"hide-cell"
]
},
"source": [
"### Lösungsvorschlag"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"tags": [
"loesung",
"hide-cell"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mindestens ein Werte von '10100101' ist wahr: True\n",
"Alle Werte von '10100101' sind falsch: False\n",
"Mindestens ein Werte von '10100101' ist falsch: True\n",
"Alle Werte von '10100101' sind wahr: False\n"
]
}
],
"source": [
"print(\"Mindestens ein Bit von '10100101' ist wahr:\", 0b10100101 > 0)\n",
"print(\"Alle Bits von '10100101' sind falsch:\", 0b10100101 == 0)\n",
"print(\"Mindestens ein Bit von '10100101' ist falsch:\", 0b10100101 < 0b11111111)\n",
"print(\"Alle Bits von '10100101' sind wahr:\", 0b10100101 == 0b11111111)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"tags": [
"loesung",
"hide-cell"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mindestens ein Werte von '10100101' ist wahr: True\n",
"Alle Werte von '10100101' sind falsch: False\n",
"Mindestens ein Werte von '10100101' ist falsch: True\n",
"Alle Werte von '10100101' sind wahr: False\n"
]
}
],
"source": [
"print(\"Mindestens ein Bit von '10100101' ist wahr:\", (True or False or True or False or False or True or False or True) == True)\n",
"print(\"Alle Bits von '10100101' sind falsch:\", (True or False or True or False or False or True or False or True) == False)\n",
"print(\"Mindestens ein Bit von '10100101' ist falsch:\", (True and False and True and False and False and True and False and True) == False)\n",
"print(\"Alle Bits von '10100101' sind wahr:\", (True and False and True and False and False and True and False and True) == True)"
]
}
],
"metadata": {
Expand All @@ -459,7 +587,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.10.10"
}
},
"nbformat": 4,
Expand Down