13 Commits
Author SHA1 Message Date
schaermicha1 978db954d2 Merge pull request 'add analysis module' (#5) from sw4_analyis_module into master
Reviewed-on: #5
2026-03-13 18:50:20 +01:00
schaermicha1 fb97703cdd add analysis module 2026-03-12 15:07:47 +01:00
schaermicha1 86d0d6582d Merge pull request 'SW3-classes-ii' (#4) from SW3-classes-ii into master
Reviewed-on: #4
2026-03-12 11:59:36 +01:00
schaermicha1 7fc5e59d5b move to class module 2026-03-12 11:58:45 +01:00
schaermicha1 986a26890a sw3 Übungen, codewars MenuDisplay 2026-03-12 11:54:10 +01:00
schaermicha1 9e5606d464 inheritance with abstract base class 2026-03-05 16:14:59 +01:00
schaermicha1 1e03bb170f Merge pull request 'Dog with inheritance' (#3) from feature/dog_with_inheritance into master
Reviewed-on: #3
2026-02-27 17:21:19 +01:00
schaermicha1 4a72bba099 Merge branch 'master' into feature/dog_with_inheritance 2026-02-27 17:21:15 +01:00
schaermicha1 14f60e7396 Merge pull request 'simple classes, add codewars - last digit of huge number' (#2) from feature/codewars_last_digit_of_huge_number into master
Reviewed-on: #2
2026-02-27 17:21:10 +01:00
schaermicha1 1eef5f8884 Merge branch 'master' into feature/codewars_last_digit_of_huge_number 2026-02-27 17:20:00 +01:00
schaermicha1 b7c9cfb84e Dog with inheritance 2026-02-27 17:18:10 +01:00
schaermicha1 41c0c31f97 simple classes, add codewars - last digit of huge number 2026-02-27 15:49:12 +01:00
schaermicha1 984c0d971d Merge pull request 'feat: add addition function and its test-function' (#1) from uebung1 into master
Reviewed-on: #1
2026-02-20 16:46:52 +01:00
16 changed files with 334 additions and 0 deletions

No files matched your search

File renamed without changes.
+13
View File
@@ -0,0 +1,13 @@
from analysis.io import load_sales
from analysis.metrics import revenue_per_day
from analysis.plotting import plot_daily_revenue
def main() -> None:
df = load_sales("resources/sales.csv")
daily = revenue_per_day(df)
plot_daily_revenue(daily)
if __name__ == "__main__":
main()
+5
View File
@@ -0,0 +1,5 @@
import pandas as pd
def load_sales(path: str) -> pd.DataFrame:
return pd.read_csv(path, sep=",", encoding="utf-8")
+6
View File
@@ -0,0 +1,6 @@
import pandas as pd
def revenue_per_day(df: pd.DataFrame) -> pd.Series:
revenue = df["quantity"] * df["unit_price"]
return revenue.groupby(df["day"]).sum()
+9
View File
@@ -0,0 +1,9 @@
import matplotlib.pyplot as plt
import pandas as pd
def plot_daily_revenue(daily: pd.Series) -> None:
daily.plot(kind="bar")
plt.title("Daily Revenue")
plt.tight_layout()
plt.show()
+37
View File
@@ -0,0 +1,37 @@
class Menu:
def __init__(self, selects: list):
self.selects = selects
self.cursor = 0
def to_the_right(self):
self.cursor = (self.cursor + 1) % len(self.selects)
def to_the_left(self):
self.cursor = (self.cursor - 1) % len(self.selects)
def display(self):
return (
"["
+ ", ".join(
[
f"'{s}'" if i != self.cursor else f"['{s}']"
for i, s in enumerate(self.selects)
]
)
+ "]"
)
if __name__ == "__main__":
menu = Menu(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"])
print(menu.display())
menu.to_the_right()
print(menu.display())
menu.to_the_left()
menu.to_the_left()
menu.to_the_left()
print(menu.display())
menu.to_the_left()
menu.to_the_left()
print(menu.display())
View File
Whitespace-only changes.
+4
View File
@@ -0,0 +1,4 @@
from codewars.lastDigitOfHugeNumber import last_digit
if __name__ == "__main__":
print(last_digit([1, 2, 3, 4, 5]))
+9
View File
@@ -0,0 +1,9 @@
def last_digit(lst):
rev_lst = list(reversed(lst))
n = 1
for number in rev_lst:
n = number ** (n if n < 4 else n % 4 + 4)
return n % 10
View File
Whitespace-only changes.
+32
View File
@@ -0,0 +1,32 @@
from dataclasses import dataclass
@dataclass(frozen=True)
class Konto:
inhaber: str
saldo: float
def __init__(self, inhaber: str, saldo: float):
if not inhaber:
raise ValueError("inhaber is required")
if saldo < 0:
raise ValueError("saldo must be positive")
object.__setattr__(self, "inhaber", inhaber)
object.__setattr__(self, "saldo", saldo)
def einzahlen(self, betrag: float):
object.__setattr__(self, "saldo", self.saldo + betrag)
def abheben(self, betrag: float):
object.__setattr__(self, "saldo", self.saldo - betrag)
return betrag
k1 = Konto("Alice", 100.0)
k2 = Konto("Housi", 10)
k2.einzahlen(100)
print(k1.inhaber)
print(k2.saldo)
print(k1 is k2)
print(k1)
+74
View File
@@ -0,0 +1,74 @@
from abc import ABC, abstractmethod
class Dog(ABC):
amount_of_dogs = 0
name: str
age: int
weight: float
bark_sound: str
def __init__(self, name: str, age: int, weight: float, bark_sound: str) -> None:
self.name = name
self.age = age
self.weight = weight
self.bark_sound = bark_sound
Dog.amount_of_dogs += 1
def __str__(self):
return f"{self.name} is a {self.age} year old {self.__class__.__name__}"
@abstractmethod
def bark(self, times: int = 1) -> str:
pass
def birthday(self) -> str:
self.age += 1
return f"Happy Birthday, {self.name}! You're now {self.age} years old!"
def is_puppy(self) -> bool:
return self.age < 2
def __eq__(self, other):
return self.name == other.name
class Shepperd(Dog):
bark_sound: str = "Woo!"
def __init__(self, name: str, age: int, weight: float) -> None:
Dog.__init__(self, name, age, weight, Shepperd.bark_sound)
def bark(self, times: int = 1) -> str:
return f"{self.name} says:" + (f" {self.bark_sound}" * times)
class Poodle(Dog):
bark_sound: str = "Wow!"
def __init__(self, name: str, age: int, weight: float) -> None:
Dog.__init__(self, name, age, weight, Poodle.bark_sound)
def bark(self, times: int = 1) -> str:
return f"{self.name} says:" + (f" {self.bark_sound}" * times)
class Bulldog(Dog):
bark_sound: str = "WUUUU!"
def __init__(self, name: str, age: int, weight: float) -> None:
Dog.__init__(self, name, age, weight, Bulldog.bark_sound)
dog1 = Shepperd("Bello", 5, 22.5)
print(dog1)
print(dog1.bark())
print(dog1.birthday())
print(Dog.amount_of_dogs)
dog2 = Poodle("Bello", 10, 20)
print(dog2.bark(3))
print(dog2.is_puppy())
print(Dog.amount_of_dogs)
print(dog2 == dog1)
+114
View File
@@ -0,0 +1,114 @@
from abc import ABC, abstractmethod
class Speaker(ABC):
@abstractmethod
def speak(self):
pass
class Sleeper(ABC):
@abstractmethod
def sleep(self):
pass
class Dog(Speaker, Sleeper):
def speak(self):
print("Wau")
def sleep(self):
print("Zzzzz")
dog = Dog()
dog.speak()
dog.sleep()
class Storage(ABC):
@abstractmethod
def save(self, key: str, value: str) -> None:
pass
@abstractmethod
def load(self, key: str) -> str:
pass
class MemoryStorage(Storage):
def __init__(self):
self.storage = {}
def save(self, key: str, value: str) -> None:
self.storage.update({key: value})
def load(self, key: str) -> str:
return self.storage.get(key)
storage: Storage = MemoryStorage()
storage.save("key", "value")
print(storage.load("key"))
class Person:
def __init__(self, name: str):
self.name = name
class Student(Person):
def __init__(self, name: str, semester: int):
super().__init__(name)
self.semester = semester
s = Student("Mein Name", 3)
print(s.name)
print(s.semester)
class A:
def ping(self) -> None:
print(" A ")
class B(A):
def ping(self) -> None:
print(" B ")
super().ping()
class C(A):
def ping(self) -> None:
print(" C ")
super().ping()
class D(B, C):
pass
D().ping()
class Animal(ABC):
@abstractmethod
def speak(self):
return "..."
def chorus(self, n: int):
if n <= 0:
raise ValueError(" n muss positiv sein ")
return " ".join(self.speak() for _ in range(n))
class Cat(Animal):
def speak(self):
return super().speak()
def chorus(self, n: int):
return super().chorus(n)
print(Cat().chorus(3))
File renamed without changes.
+11
View File
@@ -0,0 +1,11 @@
day,product,quantity,unit_price,region
Mon,Notebook,3,899.0,West
Mon,Mouse,12,25.0,West
Tue,Notebook,2,899.0,Ost
Tue,Keyboard,5,70.0,Ost
Wed,Monitor,4,220.0,West
Wed,Mouse,10,25.0,Nord
Thu,Keyboard,6,70.0,Sued
Thu,Monitor,3,220.0,Ost
Fri,Notebook,1,899.0,Nord
Fri,Mouse,15,25.0,Sued
1 day product quantity unit_price region
2 Mon Notebook 3 899.0 West
3 Mon Mouse 12 25.0 West
4 Tue Notebook 2 899.0 Ost
5 Tue Keyboard 5 70.0 Ost
6 Wed Monitor 4 220.0 West
7 Wed Mouse 10 25.0 Nord
8 Thu Keyboard 6 70.0 Sued
9 Thu Monitor 3 220.0 Ost
10 Fri Notebook 1 899.0 Nord
11 Fri Mouse 15 25.0 Sued
@@ -0,0 +1,20 @@
from codewars.lastDigitOfHugeNumber import last_digit
def test_last_digit():
test_data = [
([], 1),
([0, 0], 1),
([0, 0, 0], 0),
([1, 2], 1),
([3, 4, 5], 1),
([4, 3, 6], 4),
([7, 6, 21], 1),
([12, 30, 21], 6),
([2, 2, 2, 0], 4),
([937640, 767456, 981242], 0),
([123232, 694022, 140249], 6),
([499942, 898102, 846073], 6),
]
for test_input, test_output in test_data:
assert last_digit(test_input) == test_output