Professional Documents
Culture Documents
Coroutines
Coroutines
if __name__ == "__main__":
a = float(input())
b = float(input())
equation1 = linear_equation(a, b)
next(equation1)
equation1.send(6)
***************************
define a decorator 'coroutine_decorator' which can decorate any corouting function
the decorator must create the coroutine, call next on it and return the coroutine
that is ready for accepting any input
for ex
@coroutine_decorator
def linear_equation(a, b):
....
e1 = linear_equation(3, 4)
e1.send(6)
if __name__ == "__main__":
a = float(input())
b = float(input())
equation1 = linear_equation(a, b)
equation1.send(6)
**********************
Define coroutine 'linear_equation' and coroutine_decorator functions as requested
in previous test case
define a coroutine function numberParser which is capable of converting the passed
input into an integer and also sends the integers to two linear equation coroutines
- 'equation1' and 'equation2'
equation1 represents linear equation coroutine with a =3 and b=4
equation2 represents linear equation coroutine with a=2 and b=-1
def main(x):
n = numberParser()
n.send(x)
if __name__ == "__main__":
x = float(input())
res = main(x);