Compare commits
6 Commits
feature/in
...
main
| Author | SHA1 | Date |
|---|---|---|
|
|
20d0cf13f9 | |
|
|
c374aa097a | |
|
|
da48e90bec | |
|
|
1339e39248 | |
|
|
a7ee33bdb0 | |
|
|
828937930f |
|
|
@ -1,11 +1,20 @@
|
|||
FROM python:3.11-slim
|
||||
FROM mcr.microsoft.com/devcontainers/python:3.11
|
||||
|
||||
RUN apt-get update && apt-get install -y build-essential
|
||||
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||
&& apt-get -y install --no-install-recommends build-essential \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ARG USERNAME=vscode
|
||||
ARG USER_UID=1000
|
||||
ARG USER_GID=$USER_UID
|
||||
# --- C-BIBLIOTHEK BAUEN (adder.c) ---
|
||||
COPY adder.c /tmp/adder.c
|
||||
# Kompiliert und speichert an einem systemweiten Ort
|
||||
RUN gcc -shared -o /usr/local/lib/libadder.so /tmp/adder.c
|
||||
|
||||
RUN groupadd --gid $USER_GID $USERNAME && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
|
||||
USER $USERNAME
|
||||
WORKDIR /workspace
|
||||
# --- PYTHON-ABHÄNGIGKEITEN ---
|
||||
# Kopiert requirements.txt aus dem Projekt-Root
|
||||
COPY requirements.txt .
|
||||
# Installiert die Pakete
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Setzt das Arbeitsverzeichnis im Container (dies sollte der Mount-Punkt sein)
|
||||
WORKDIR /workspace
|
||||
|
|
@ -1,19 +1,32 @@
|
|||
{
|
||||
"name": "Python 3.11 Dev Container",
|
||||
"dockerFile": "Dockerfile",
|
||||
"mounts": [
|
||||
"source=${localWorkspaceFolder},target=/workspace,type=bind"
|
||||
],
|
||||
"settings": {
|
||||
"python.linting.enabled": true,
|
||||
"python.linting.pylintEnabled": true,
|
||||
"python.formatting.provider": "black"
|
||||
},
|
||||
"extensions": [
|
||||
"ms-python.python",
|
||||
"ms-python.vscode-pylance"
|
||||
],
|
||||
|
||||
"postCreateCommand": "pip install --upgrade pip && pip install pytest black",
|
||||
"remoteUser": "vscode"
|
||||
"name": "Python 3.11 Dev Container",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
"context": "../02_python_interestingPoints"
|
||||
},
|
||||
"mounts": [
|
||||
"source=${localWorkspaceFolder},target=/workspace,type=bind"
|
||||
],
|
||||
"remoteUser": "vscode",
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"settings": {
|
||||
"python.testing.pytestEnabled": true,
|
||||
"python.testing.pytestArgs": [
|
||||
"."
|
||||
],
|
||||
"python.linting.enabled": true,
|
||||
"python.linting.pylintEnabled": true,
|
||||
"python.formatting.provider": "black"
|
||||
},
|
||||
"extensions": [
|
||||
"ms-python.python",
|
||||
"ms-python.vscode-pylance"
|
||||
],
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/git:1": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"postCreateCommand": "pip install --upgrade pip"
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,26 +1,16 @@
|
|||
# Datei: test_sum_calculator.py
|
||||
|
||||
from sum_calculator import calculate_cumulative_sum
|
||||
|
||||
def test_sum_for_zero():
|
||||
"""Testet den Randfall, wenn die Obergrenze 0 ist."""
|
||||
# Arrange: Testdaten
|
||||
"""Randfall, dass die Obergrenze 0 ist"""
|
||||
limit = 0
|
||||
# Act: Funktion aufrufen
|
||||
result = calculate_cumulative_sum(limit)
|
||||
# Assert: Überprüfen des Ergebnisses (0 erwartet)
|
||||
|
||||
assert result == 0
|
||||
|
||||
def test_sum_for_five():
|
||||
"""Testet den allgemeinen Fall für die Zahl 5 (0+1+2+3+4+5 = 15)."""
|
||||
# Arrange: Testdaten
|
||||
"""Fall, dass Limit 5 ist"""
|
||||
|
||||
limit = 5
|
||||
# Act: Funktion aufrufen
|
||||
result = calculate_cumulative_sum(limit)
|
||||
# Assert: Überprüfen des Ergebnisses (15 erwartet)
|
||||
assert result == 15
|
||||
|
||||
def test_sum_is_correct_type():
|
||||
"""Testet, ob die Funktion einen Integer zurückgibt."""
|
||||
# Arrange, Act, Assert
|
||||
assert isinstance(calculate_cumulative_sum(3), int)
|
||||
|
||||
assert result == 15
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#include <stdint.h>
|
||||
|
||||
// Die Funktion, die Python aufrufen wird
|
||||
// extern "C" ist wichtig, um die Namenskonvention (Name Mangling) zu verhindern
|
||||
extern int32_t addiere_zahlen(int32_t a, int32_t b) {
|
||||
// Gibt die Summe der beiden übergebenen Zahlen zurück
|
||||
return a + b;
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
max = 100
|
||||
|
||||
gerade_quadrate_lang = []
|
||||
for i in range(1, max):
|
||||
if i % 2 == 0:
|
||||
gerade_quadrate_lang.append(i * i)
|
||||
|
||||
gerade_quadrate_kurz = [i * i for i in range(1, max) if i % 2 == 0]
|
||||
|
||||
print(f"Liste (iterativ): {gerade_quadrate_lang}")
|
||||
print(f"Liste (funktional): {gerade_quadrate_kurz}")
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import numpy as np
|
||||
|
||||
messwerte = np.array([25.5, 30.1, 28.9, 35.0, 29.8, 31.2])
|
||||
|
||||
durchschnitt = np.mean(messwerte)
|
||||
|
||||
print(f"Der durchschnittliche Wert beträgt: {durchschnitt:.2f}")
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import os
|
||||
|
||||
aktueller_ordner = "."
|
||||
|
||||
print(f"Inhalt des Ordners '{aktueller_ordner}':")
|
||||
|
||||
for element in os.listdir(aktueller_ordner):
|
||||
|
||||
if os.path.isfile(element):
|
||||
print(f" - Datei: {element}")
|
||||
else:
|
||||
print(f" - Ordner: {element}")
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import ctypes
|
||||
import os
|
||||
|
||||
lib_path = "/usr/local/lib/libadder.so"
|
||||
c_lib = ctypes.CDLL(lib_path)
|
||||
|
||||
c_lib.addiere_zahlen.argtypes = [ctypes.c_int32, ctypes.c_int32]
|
||||
c_lib.addiere_zahlen.restype = ctypes.c_int32
|
||||
|
||||
zahl_a = 33
|
||||
zahl_b = 34
|
||||
|
||||
ergebnis = c_lib.addiere_zahlen(zahl_a, zahl_b)
|
||||
|
||||
print(f"Zahlen: {zahl_a} + {zahl_b}")
|
||||
print(f"Ergebnis von C-Funktion: {ergebnis}")
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
numpy
|
||||
flask
|
||||
pytest
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
from flask import Flask
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/hallo")
|
||||
def hallo_welt():
|
||||
return "<h1>Hallo vom Server!</h1>"
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=False)
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#Dictionary (Map)
|
||||
#Erstellen des Dictionarys
|
||||
persons = {"Alice":30, "Bob":25}
|
||||
print(persons)
|
||||
|
||||
#Hinzufügen neuer Wert
|
||||
persons["Peter"] = 40
|
||||
|
||||
#Ändern eines Values
|
||||
persons["Bob"] = 45
|
||||
|
||||
#Löschen eines Elements mithilfe von Key
|
||||
persons.pop("Bob")
|
||||
print(persons)
|
||||
|
||||
#Löschen des letzten Wertes mit Rückgabe
|
||||
key,value = persons.popitem()
|
||||
print(key, value)
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
#Klassische Situation mit Klasse und Konstruktor __init__ ist dabei Konstruktor
|
||||
#self ist vergleichbar mit this aus java
|
||||
class Person:
|
||||
def __init__(self, name, age):
|
||||
self.name = name
|
||||
self.age = age
|
||||
def ausgabe(self):
|
||||
print(self.name, self.age)
|
||||
|
||||
#Instanz von Person und anwenden der Funktion
|
||||
p1 = Person("Peter", 30)
|
||||
p1.ausgabe()
|
||||
|
||||
#Funktion anlegen ohne Typen
|
||||
def rechne(a, b):
|
||||
return a+b
|
||||
|
||||
#Funktion mit Typen
|
||||
def rechne1(a: int, b: int) -> int:
|
||||
return a+b
|
||||
|
||||
print(rechne(1, 2))
|
||||
print(rechne1(1, 2))
|
||||
|
||||
#Python erlaubt Mehrfachvererbung
|
||||
class A: pass
|
||||
class B: pass
|
||||
class C(A, B): pass
|
||||
|
||||
#Einfache Art und Weise der Nutzung von Lambdaausdrücken
|
||||
square = lambda x: x*x
|
||||
print(square(5))
|
||||
|
||||
def func(a,b):
|
||||
return a+b
|
||||
|
||||
print(func(10, 2))
|
||||
|
||||
def func(a):
|
||||
return a*a
|
||||
|
||||
#print(func(10, 2)) Dies funktioniert nicht, die die untere die obere überschreibt!
|
||||
print(func(10))
|
||||
|
||||
#funktionen als objekte
|
||||
def apply(func, value):
|
||||
return func(value)
|
||||
print(apply(lambda x: x+1, 5))
|
||||
|
||||
#enums
|
||||
from enum import Enum
|
||||
class Status(Enum):
|
||||
OK = 1
|
||||
NOT_FOUND = 2
|
||||
ERROR = 3
|
||||
|
||||
print(Status.OK.value)
|
||||
print(Status.OK)
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
#In diesem Abschnitt soll es um Listen in Python gehen
|
||||
|
||||
#Listen anlegen
|
||||
nums = [1,2,3,4]
|
||||
|
||||
#Zur Liste hinzufügen
|
||||
nums.append(5)
|
||||
|
||||
# ausgabe von Listenelementen
|
||||
print(nums)
|
||||
print(nums[2])
|
||||
print(nums[2:5])
|
||||
|
||||
#Einfügen eines Listenelements
|
||||
nums.insert(1, 20)
|
||||
|
||||
#Einfügen mehrerer Listenelemente
|
||||
nums.extend([7,8,9])
|
||||
|
||||
#Pop des letzten Elements
|
||||
numTest = nums.pop()
|
||||
print (numTest)
|
||||
|
||||
#Pop des Elements an erster stelle
|
||||
numTest2 = nums.pop(1)
|
||||
print(numTest2)
|
||||
|
||||
#Leeren der Liste
|
||||
nums.clear()
|
||||
print(nums)
|
||||
|
||||
#mutability von Listen
|
||||
a = [1,2,3]
|
||||
b=a
|
||||
b.append(4)
|
||||
print(a)
|
||||
#b verweist auf a und änderungen werden auf a durchgeführt
|
||||
#es werden referenzen übergeben
|
||||
c = a.copy()
|
||||
c.append(5)
|
||||
print(a, c)
|
||||
|
||||
#Erweiterte Listen
|
||||
liste = [1, "abc", 3.5]
|
||||
print(liste)
|
||||
|
||||
#Erweitertes erstellen von Listen
|
||||
nums = [1,2,3,4,5,6]
|
||||
#in erstellungsanweisungen können for schleifen und if abfragen verwendet werden
|
||||
squares = [x*x for x in nums if x%2 == 0]
|
||||
print(squares)
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#Sets
|
||||
values = {1,2,2,3}
|
||||
print (values)
|
||||
|
||||
#Hinzufügen einzelner werte
|
||||
values.add(4)
|
||||
|
||||
#hinzufügen einer liste
|
||||
values.update([5,6,7])
|
||||
|
||||
#entfernen eines elements mit wert 1 (unsicher, wirft fehler falls nicht vorhanden)
|
||||
values.remove(1)
|
||||
|
||||
#entfernen eines elements mit wert 2 (sicher, keine Fehler falls es nicht existiert)
|
||||
values.discard(2)
|
||||
|
||||
#entfernt ein beliebiges Element
|
||||
values.pop()
|
||||
print(values)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#Tupel
|
||||
point = (3,4,5)
|
||||
x,y,z = point
|
||||
print(x,y,z)
|
||||
|
||||
points = [(3,4), (5,6), (7,8)]
|
||||
a, b = points[2]
|
||||
print(points, points[2], a, b)
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
# Aufgabenstellung
|
||||
|
||||
1. Schreiben Sie eine Listenberechnung in Python, bei der die Zahlen `[1,2,3,4,5,6,7,8,9]` quadriert werden, wenn diese gerade sind.
|
||||
2. Gegeben ist folgender Ausdruck `persons = {"Alice":30, "Bob":45, "Charlie":18}` schreiben Sie dazu eine Funktion, die das Durchschnittsalter berechnet.
|
||||
3. Schreiben Sie eine Klasse Person mit den Attributen `name` und `alter` und eine Funktion `is_adult`, die prüft ob eine Person erwachsen ist.
|
||||
4. Schreiben Sie eine Funktion `applyToList`, die eine Funktion und eine Liste entgegen nimmt und die Funktion auf alle Elemente der Liste anwendet (Tipp: Lambda).
|
||||
5. Schreiben Sie einen Taschenrechner, der über die Kommandozeile bedient werden kann und die Grundrechenarten beherrscht.
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
# Python Code Repository
|
||||
|
||||
This Repository contains examples of how to use most basics in python. Everything shown in our presentation is also shown in this repo.
|
||||
|
||||
## Usage
|
||||
|
||||
This container is very similar to other devcontainers.
|
||||
|
||||
Follow these steps to get started:
|
||||
|
||||
1. Clone this repository to a local folder of your choice.
|
||||
2. Navigate to this exact location to open the python container.
|
||||
3. Open Visual Studio Code in this folder.
|
||||
4. Click *Reopen in Container*.
|
||||
|
||||
To start any python program use the command `python ./dateiname.py` and it will be executed.
|
||||
Loading…
Reference in New Issue