0% found this document useful (0 votes)
79 views1 page

Coroutine Decorator for Equations

The document defines a coroutine decorator and two coroutine functions: 'linear_equation' and 'numberParser'. The 'linear_equation' function calculates a quadratic expression based on input values, while 'numberParser' sends an input number to two instances of 'linear_equation'. The 'main' function initializes 'numberParser' and sends a value to it.

Uploaded by

arif895178
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views1 page

Coroutine Decorator for Equations

The document defines a coroutine decorator and two coroutine functions: 'linear_equation' and 'numberParser'. The 'linear_equation' function calculates a quadratic expression based on input values, while 'numberParser' sends an input number to two instances of 'linear_equation'. The 'main' function initializes 'numberParser' and sends a value to it.

Uploaded by

arif895178
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

# Define the function 'coroutine_decorator' below

def coroutine_decorator(coroutine_func):
def start(*args, **kwargs):
cr = coroutine_func(*args, **kwargs)
next(cr)
return cr
return start
# Define the coroutine function 'linear_equation' below
@coroutine_decorator
def linear_equation(a, b):
while True:
x=yield
s=a*(x**2)+b
print("Expression, {}*x^2 + {}, with x being 6.0 equals {}".format(a,b,s))

# Define the coroutine function 'numberParser' below


@coroutine_decorator
def numberParser():
while True:
y=yield
equation1 = linear_equation(3, 4)
equation2 = linear_equation(2, -1)
[Link](y)
[Link](y)
# code to send the input number to both the linear equations

def main(x):
n = numberParser()
[Link](x)

You might also like