def count_up_to(n): “””Generator that counts from 1 up to n.””” count = 1 while count <= n: yield count count += 1 # Using the generator for number in count_up_to(5): print(number)
A yield example from chatgpt
Posted on
def count_up_to(n): “””Generator that counts from 1 up to n.””” count = 1 while count <= n: yield count count += 1 # Using the generator for number in count_up_to(5): print(number)