"Berechne die Höhe eines Balls nach 0.6s mit v0=5m/s, g=9.81m/s2 mit Hilfe der Formel $y(t)=v_0t - \\frac{1}{2} gt^2$"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.2342\n"
]
}
],
"source": [
"print(5*0.6 - 0.5*9.81*0.6**2)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Variablen\n",
"\n",
"- Die Variable legt den Namen eines Objekts fest.\n",
"- Der Ausdruck auf der rechten Seite wird der Variable zugewiesen.\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"y = 3 \n",
"result = 3 + 4"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Programmieren mit Variablen\n",
"Die Verwendung von Variablen in unserem Ballproblem führt zu folgendem Code:\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.2342\n"
]
}
],
"source": [
"v0 = 5\n",
"g = 9.81\n",
"t = 0.6\n",
"y = v0*t - 0.5*g*t**2\n",
"print(y)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Kommentare\n",
"- Erklärungen in natürlicher Sprache bereitstellen.\n",
"- beginnen mit dem Zeichen #."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.2342\n"
]
}
],
"source": [
"# computes the height of a ball in vertical motion. \n",
"v0 = 5 # initial velocity\n",
"g = 9.81 # acceleration of gravity\n",
"t = 0.6 # time\n",
"y = v0*t - 0.5*g*t**2 # vertical position\n",
"print(y)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Module\n",
"- manche Funktionen, die wir benutzen wollen, sind in extra Bibliotheken verfügbar, die wir laden müssen"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.3277387786416064\n"
]
}
],
"source": [
"import random\n",
"x = random.random()\n",
"print(x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Übungen\n",
"1. Berechne die Höhe des Balls nach 1 Sekunde mit v0=5 m/s!\n",
"2. Berechne die Höhe des Balls nach 1 Sekunde mit v0=10m/s!\n",
"3. Berechne die Höhe des Balls nach 1 Sekunde mit einer zufälligen Anfangsgeschwindigkeit!\n",
"4. Berechne die Höhe des Balls nach 1 Sekunde mit v0=5 m/s auf dem Mond! Tipp: finde die Gravitationsbeschleuningung auf dem Mond raus und setze sie statt die Erdbeschleunigung ein."
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
%% Cell type:markdown id: tags:
# Höhere Programmiersprachen
- von Menschen lesbare Zahlen und Zeichenketten
- Container = automatische Zuweisung von Speicherplätzen zur Speicherung und Benennung von Daten
- Ausdrücke (Berechnungen basierend auf Operatoren, mit Vorrang, wie in der Mathematik)
- Konstrukte für wiederholte Ausführung
- Funktionen
%% Cell type:markdown id: tags:
# Einführung in Python
%% Cell type:markdown id: tags:
# Erstes Beispiel: Eine Formel
Vertikale Bewegung eines in die Luft geworfenen Balls:
## $y(t)=v_0t - \frac{1}{2} gt^2$
v0: Anfangsgeschwindigkeit, g: Erdbeschleunigung, t: Zeit
Berechne die Höhe eines Balls nach 0.6s mit v0=5m/s, g=9.81m/s2 mit Hilfe der Formel $y(t)=v_0t - \frac{1}{2} gt^2$
%% Cell type:code id: tags:
``` python
print(5*0.6-0.5*9.81*0.6**2)
```
%% Output
1.2342
%% Cell type:markdown id: tags:
# Variablen
- Die Variable legt den Namen eines Objekts fest.
- Der Ausdruck auf der rechten Seite wird der Variable zugewiesen.
%% Cell type:code id: tags:
``` python
y=3
result=3+4
```
%% Cell type:markdown id: tags:
# Programmieren mit Variablen
Die Verwendung von Variablen in unserem Ballproblem führt zu folgendem Code:
%% Cell type:code id: tags:
``` python
v0=5
g=9.81
t=0.6
y=v0*t-0.5*g*t**2
print(y)
```
%% Output
1.2342
%% Cell type:markdown id: tags:
# Kommentare
- Erklärungen in natürlicher Sprache bereitstellen.
- beginnen mit dem Zeichen #.
%% Cell type:code id: tags:
``` python
# computes the height of a ball in vertical motion.
v0=5# initial velocity
g=9.81# acceleration of gravity
t=0.6# time
y=v0*t-0.5*g*t**2# vertical position
print(y)
```
%% Output
1.2342
%% Cell type:markdown id: tags:
# Module
- manche Funktionen, die wir benutzen wollen, sind in extra Bibliotheken verfügbar, die wir laden müssen
%% Cell type:code id: tags:
``` python
importrandom
x=random.random()
print(x)
```
%% Output
0.3277387786416064
%% Cell type:markdown id: tags:
# Übungen
1. Berechne die Höhe des Balls nach 1 Sekunde mit v0=5 m/s!
2. Berechne die Höhe des Balls nach 1 Sekunde mit v0=10m/s!
3. Berechne die Höhe des Balls nach 1 Sekunde mit einer zufälligen Anfangsgeschwindigkeit!
4. Berechne die Höhe des Balls nach 1 Sekunde mit v0=5 m/s auf dem Mond! Tipp: finde die Gravitationsbeschleuningung auf dem Mond raus und setze sie statt die Erdbeschleunigung ein.