Skip to content
Snippets Groups Projects
Commit 466bb8af authored by Sadikni, Remon's avatar Sadikni, Remon
Browse files

Upload New File

parent e1937de3
Branches
No related tags found
No related merge requests found
%% 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
%% Cell type:markdown id: tags:
# Operatoren
<table>
<tr><th>Operator</th><th>steht für</th><th>Präzedenz</th></tr>
<tr><td>+</td><td>Addition</td><td>0</td></tr>
<tr><td>-</td><td>Subtraktion</td><td>0</td></tr>
<tr><td>*</td><td>Multiplikation</td><td>1</td></tr>
<tr><td>/</td><td>Division</td><td>1</td></tr>
<tr><td>**</td><td>Potenz</td><td>2</td></tr>
</table>
%% Cell type:markdown id: tags:
# Erstes Python Programm
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
import random
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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment