# -*- coding:UTF-8 -*-

"""
compatible Python: 3.6.4

Author: Andrew YE

Date: 2018-01-23

Topic: Number

Content:
    1. immutable:       means memory space will be reassigned while value changed
    2. three data type: int, float, complex
    3. type conversion: int(x), float(x), complex(x), complex(x, y)
    4. operate:         + - * /,  //, **,
"""

# --iterator using method iter() and next() begin-----------------------

# list
example_list = [1, 2, 3, 4]
# iterator object
iterator = iter(example_list)
# traverse way 1
for x in iterator:
    print(x, end=" ")

# traverse way 2
print(next(iterator))

# traverse way 3
while True:
    try:
        print(next(iterator))
    except StopIteration:
        import sys

        sys.exit()


# --iterator using method iter() and next()  end-----------------------


# --generator using yield begin-----------------------

# generator functions
def fibonacci(n):
    a, b, counter = 0, 1, 0
    while True:
        if counter > n:
            return
        yield a
        a, b = b, a + b
        counter += 1


# generator object
input_number = int(input())
f = fibonacci(input_number)

while True:
    try:
        print(next(f), end=" ")
    except StopIteration:
        import sys

        sys.exit()

# --generator using yield end-----------------------

# --generator using method () begin-----------------------

my_generator = (x for x in range(3))
print(type(my_generator))
for i in my_generator:
    print(i)

# --generator using method () end-----------------------
