Files
Function/aufgaben/einstellung/Pr_5/pr/ungeradezahlen.py
T
2026-11-05 15:56:26 +01:00

35 lines
759 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 ---")
"""с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 """