educative.io

Code syntax needs to update

for yield from code is syntax wise wrong
------------[correct format]--------------------

def subgenerator():
  value = yield
  return value ** 2

def generator():
  while 1:
    term = yield from subgenerator()
    term += term
    yield term
    # return term
c = generator()
next(c)
print(c.send(2))

same goes for the above example

def coroutine():
    while 1:
        print('Started')
        x = yield               # yield with an expression
        print('Recieved',x)

cr = coroutine()
next(cr)                    # Activating coroutine
cr.send('Educative')        # Sending value to coroutinne

as yield handels the Exception StopIteration