This commit is contained in:
wittmannzl103469 committed 2026-11-17 11:23:05 +01:00
1 parent 571cddedba
commit 1934fdfc63
8 files changed
+134 -46

No files matched your search

+6 -33
View File
@@ -1,35 +1,8 @@
def odd(limit):
"""Generiert ungerade Zahlen bis zu einem exklusiven Limit."""
zahl = 1
while zahl < limit:
yield zahl
zahl += 2
# --- Code für die Ausgabe im Terminal ---
print("--- Start der Schleife ---")
# Wir rufen die Funktion mit dem Limit 10 auf
for ungerade_zahl in odd(10):
print(f"Gefundene Zahl: {ungerade_zahl}")
print("--- Ende der Schleife ---")
def odd(n: int):
for i in range(1, n + 1, 2):
yield i
"""сlass OddIterator:
def __init__(self, limit):
self.limit = limit
self.aktuelle_zahl = 1
def __iter__(self):
return self
def __next__(self):
if self.aktuelle_zahl >= self.limit:
raise StopIteration
ergebnis = self.aktuelle_zahl
self.aktuelle_zahl += 2
return ergebnis """
# Test
print(list(odd(7))) # [1, 3, 5, 7]
print(list(odd(8))) # [1, 3, 5, 7]