Menu Display

This commit is contained in:
Julia Hauer 2026-03-15 20:39:17 +01:00
parent 2d801b7376
commit 17222e110b
8 changed files with 210 additions and 1 deletions

View File

@ -2,13 +2,16 @@ class Human:
def __init__(self):
pass
class Woman(Human):
pass
class Man(Human):
pass
def God():
adam = Man()
eve = Woman()
return[adam, eve]
return [adam, eve]

View File

@ -0,0 +1,39 @@
class Menu:
def __init__(self, lst):
self.lst = lst
self.cursor_pos = 0
def to_the_right(self):
if self.cursor_pos < len(self.lst) - 1:
self.cursor_pos += 1
else:
self.cursor_pos = 0
def to_the_left(self):
if self.cursor_pos > 0:
self.cursor_pos -= 1
else:
self.cursor_pos = len(self.lst) - 1
def display(self):
result = []
for i, char in enumerate(self.lst):
if i == self.cursor_pos:
result.append([f"{char}"])
else:
result.append(f"{char}")
return str(result)
menu = Menu([1, 2, 3])
print(menu.display())
menu.to_the_right()
print(menu.display())
menu.to_the_right()
print(menu.display())
menu.to_the_right()
print(menu.display())
menu.to_the_left()
print(menu.display())
menu.to_the_left()
print(menu.display())

View File

@ -0,0 +1,22 @@
class Robot:
def speak(self, mood="happy") -> str:
if mood == "happy":
return "Robo"
class Dog:
def speak(self):
return "Wuff"
class Cat:
def speak(self):
return "Miau"
def chorus(animals) -> None:
for a in animals:
print(a.speak())
chorus([Dog(), Cat(), Robot()])

View File

@ -0,0 +1,22 @@
from abc import ABC, abstractmethod
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[key] = value
def load(self, key: str) -> str:
return self.storage[key]

View File

@ -0,0 +1,51 @@
from abc import ABC, abstractmethod
class Hund(ABC):
anzahl_hunde = 0
def __init__(self, name: str, alter: int, gewicht: float):
self.name = name
self.alter = alter
self.gewicht = gewicht
Hund.anzahl_hunde += 1
def __repr__(self):
return f"Hund=(name='{self.name}', rasse='{self.__class__.__name__}' , alter={self.alter}, gewicht={self.gewicht}kg)"
def __str__(self):
return f"Hund '{self.name}' ist ein '{self.alter}'-jaehriger '{self.__class__.__name__}' und wiegt '{self.gewicht}' kg."
@abstractmethod
def bellen(self, n: int = 1) -> None:
pass
def bday(self):
self.alter += 1
print(f"Alles Gute '{self.name}'. Du bist jetzt '{self.alter}' Jahre alt.")
def ist_welpe(self):
return self.alter < 2
class Pudel(Hund):
def bellen(self, n=1):
print(" ".join(["wau"] * n))
class Labrador(Hund):
def bellen(self, n=1):
print(" ".join(["wuff"] * n))
hund1 = Labrador("Bello", 2, 15)
hund1.bday()
print(hund1.ist_welpe())
hund2 = Pudel("Pudi", 7, 4)
hund1.bellen(8)
hund2.bellen(3)
print(repr(hund1))
print(str(hund1))

31
src/Klassen2/chorus.py Normal file
View File

@ -0,0 +1,31 @@
from abc import ABC, abstractmethod
class Animal(ABC):
@abstractmethod
def speak(self) -> str:
return "..."
def chorus(self, n: int) -> str:
if n <= 0:
raise ValueError("n muss positiv sein")
return " ".join(self.speak() for _ in range(n))
class Dog(Animal):
def speak(self) -> str:
return "wuff"
class Cat(Animal):
def speak(self) -> str:
return "miau"
class Cow(Animal):
def speak(self) -> str:
return "muh"
Berta = Cow()
print(Berta.chorus(1))

17
src/Klassen2/mro.py Normal file
View File

@ -0,0 +1,17 @@
class A:
pass
class B(A):
pass
class C(A):
pass
class D(B, C):
pass
print(D.mro())

24
src/Klassen2/ping.py Normal file
View File

@ -0,0 +1,24 @@
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):
def ping(self) -> None:
print("D")
super().ping()
D().ping()