Sep-14-2018, 07:52 AM
I couldnt get second output.I donno why
def coroutine_decorator(coroutine_func): def wrapper(*x,**y): c = coroutine_func(*x,**y) next(c) return c return wrapper @coroutine_decorator def linear_equation(a, b): x=yield c=a*(x**2)+b print("Expression, {}*x^2 + {}, with x being {} equals {}".format(a,b,x,c)) @coroutine_decorator def numberParser(): y=yield equation1 = linear_equation(3, 4) equation2 = linear_equation(2, -1) equation1.send(y) equation2.send(y) def main(x): n = numberParser() n.send(x) main(6)Expected output
Output:Expression, 3*x^2 + 4, with x being 6.0 equals 112.0
Expression, 2*x^2 + -1, with x being 6.0 equals 71.0
My outputOutput:Expression, 3*x^2 + 4, with x being 6.0 equals 112.0
ErrorError:Traceback (most recent call last):
File "solution.py", line 37, in <module>
res = main(x);
File "solution.py", line 30, in main
n.send(x)
File "solution.py", line 26, in numberParser
equation1.send(y)
StopIteration