added tut02
This commit is contained in:
@ -20,7 +20,7 @@
|
|||||||
<img src="../../src/img/discord.png" height="200">
|
<img src="../../src/img/discord.png" height="200">
|
||||||
<img src="../../src/img/telegram.png" height="200">
|
<img src="../../src/img/telegram.png" height="200">
|
||||||
<img src="../../src/img/feedback-google-forms.png" height="200">
|
<img src="../../src/img/feedback-google-forms.png" height="200">
|
||||||
<img src="../../src/img/tutorium-01.png" height="200">
|
<img src="./src/tutorium-01.png" height="200">
|
||||||
|
|
||||||
## Zusammenfassung Vorlesung
|
## Zusammenfassung Vorlesung
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
@ -1 +1,138 @@
|
|||||||
|
|
||||||
# Zusammenfassung der Vorlesung
|
# Zusammenfassung der Vorlesung
|
||||||
|
|
||||||
|
## Variablen und Zuweisungen
|
||||||
|
|
||||||
|
```python
|
||||||
|
variable = 42
|
||||||
|
print(variable)
|
||||||
|
print(variable + variable)
|
||||||
|
```
|
||||||
|
|
||||||
|
- Case-Sensitive
|
||||||
|
- A-z, 0-9, _
|
||||||
|
- Keine Schlüsselwörte
|
||||||
|
|
||||||
|
### Kurzzuweisung
|
||||||
|
|
||||||
|
Operationen und Zuweisung können in einem Schritt durchgeführt werden mit `${Operation}=`
|
||||||
|
|
||||||
|
```python
|
||||||
|
number = 42
|
||||||
|
number **= 42
|
||||||
|
assert number == 42 ** 42
|
||||||
|
number += 42
|
||||||
|
assert number == 42 ** 42 + 42
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Assert
|
||||||
|
|
||||||
|
- Erwartet einen wahren Ausdruck, wenn dieser nicht erfüllt ist gibt es einen Fehler
|
||||||
|
- Gut um etwas schnell zu testen
|
||||||
|
|
||||||
|
```py
|
||||||
|
number = 42
|
||||||
|
assert number == 42
|
||||||
|
bigger_number = number ** number
|
||||||
|
assert number ** number == bigger_number
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Typen
|
||||||
|
|
||||||
|
```py
|
||||||
|
number = 42
|
||||||
|
string = '42'
|
||||||
|
assert number != string
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Funktionen
|
||||||
|
|
||||||
|
### Standardfunktionen
|
||||||
|
|
||||||
|
- Typen konvertieren
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> int(2.6)
|
||||||
|
2
|
||||||
|
>>> float(2)
|
||||||
|
2.0
|
||||||
|
>>> str(2.0)
|
||||||
|
'2.0'
|
||||||
|
```
|
||||||
|
|
||||||
|
- Input/Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> input("Hier Input geben: ")
|
||||||
|
Hier Input geben: 42
|
||||||
|
'42'
|
||||||
|
>>> print(42)
|
||||||
|
42
|
||||||
|
```
|
||||||
|
|
||||||
|
### Funktionen kombinieren
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> int(str(2))
|
||||||
|
2
|
||||||
|
>>> str(int('2'))
|
||||||
|
'2'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Neue Funktionen definieren
|
||||||
|
|
||||||
|
Mit `def` können neue Funktionen definiert werden
|
||||||
|
|
||||||
|
```python
|
||||||
|
def my_print_func(some_text):
|
||||||
|
print(some_text)
|
||||||
|
|
||||||
|
def my_add(a, b):
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
my_print_func(my_add(1, 2)) # prints 3
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Imports
|
||||||
|
|
||||||
|
Mit `import` können Module (andere Python-Datein) importiert und benutzt werden
|
||||||
|
|
||||||
|
```python
|
||||||
|
import math
|
||||||
|
|
||||||
|
print(math.cos(math.pi)) # prints -1.0
|
||||||
|
```
|
||||||
|
|
||||||
|
Mit `from` und `import` können Sachen aus einem Modul spezifisch importiert werden
|
||||||
|
|
||||||
|
```python
|
||||||
|
from math import cos, pi
|
||||||
|
|
||||||
|
print(cos(pi)) # prints -1.0
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Scopes
|
||||||
|
|
||||||
|
Variabeln existieren in so genannten Scopes, am besten veranschaulicht man sich das einfach:
|
||||||
|
|
||||||
|
```python
|
||||||
|
GLOBAL_X = 42
|
||||||
|
|
||||||
|
def my_func():
|
||||||
|
x_in_func = 42 # x_in_func wird hier im Scope der Funktion erstellt
|
||||||
|
print(GLOBAL_X) # GLOBAL_X ist im globalen Scope,
|
||||||
|
# also auch hier im Funktions-Scope, weil dieser Scope auch im globalen Scope ist
|
||||||
|
|
||||||
|
print(x_in_func) # wirft einen Fehler, weil x_in_func nicht im Scope ist
|
||||||
|
print(GLOBAL_X) # Global Scope
|
||||||
|
```
|
||||||
|
@ -2,4 +2,58 @@
|
|||||||
|
|
||||||
## Häufige Fehler
|
## Häufige Fehler
|
||||||
|
|
||||||
### Aufgabe 1.2
|
### Aufgabe 1.1
|
||||||
|
|
||||||
|
Wer weiterhin Probleme bei der Installation hat, bitte nach dem Tutorat
|
||||||
|
|
||||||
|
### Aufgabe 1.2
|
||||||
|
|
||||||
|
- Terminierung war nicht erfüllt für $x,y=0$ aber nicht $x = y$
|
||||||
|
- Dadurch auch kein Algorithmus laut Definition der Vorlesung, gab keinen Abzug wenn man alle Bedingungen als erfüllt ansah
|
||||||
|
|
||||||
|
### Aufgabe 1.3
|
||||||
|
|
||||||
|
- Es ging vor allem um den Unterschied zwischen der Python-Shell und dem normalen ausführen von `.py` Dateien
|
||||||
|
|
||||||
|
### Aufgabe 1.4
|
||||||
|
|
||||||
|
- Achtet auf die genau Anforderung!!!
|
||||||
|
|
||||||
|
```sh
|
||||||
|
Python
|
||||||
|
Python
|
||||||
|
Python
|
||||||
|
```
|
||||||
|
|
||||||
|
heißt nicht
|
||||||
|
|
||||||
|
```sh
|
||||||
|
|
||||||
|
|
||||||
|
Python
|
||||||
|
Python
|
||||||
|
Python
|
||||||
|
```
|
||||||
|
|
||||||
|
oder
|
||||||
|
|
||||||
|
```sh
|
||||||
|
|
||||||
|
|
||||||
|
Python
|
||||||
|
Python
|
||||||
|
Python
|
||||||
|
```
|
||||||
|
|
||||||
|
oder
|
||||||
|
|
||||||
|
```sh
|
||||||
|
Python
|
||||||
|
Python
|
||||||
|
Python
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Punkteverteilung
|
||||||
|
|
||||||
|

|
@ -18,4 +18,4 @@
|
|||||||
<img src="../../src/img/discord.png" height="200">
|
<img src="../../src/img/discord.png" height="200">
|
||||||
<img src="../../src/img/telegram.png" height="200">
|
<img src="../../src/img/telegram.png" height="200">
|
||||||
<img src="../../src/img/feedback-google-forms.png" height="200">
|
<img src="../../src/img/feedback-google-forms.png" height="200">
|
||||||
<img src="../../src/img/tutorium-02.png" height="200">
|
<img src="./src/tutorium-02.png" height="200">
|
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
Reference in New Issue
Block a user