What is the output of the following code? def stringParser(): while True: name = yield (fname, lname) = name.split() f.send(fname) f.send(lname) def stringLength(): while True: string = yield print("Length of '{}' : {}".format(string, len(string))) f = stringLength(); next(f) s = stringParser() next(s) s.send('Jack Black')

Questions & AnswersCategory: Programming LanguageWhat is the output of the following code? def stringParser(): while True: name = yield (fname, lname) = name.split() f.send(fname) f.send(lname) def stringLength(): while True: string = yield print("Length of '{}' : {}".format(string, len(string))) f = stringLength(); next(f) s = stringParser() next(s) s.send('Jack Black')
Adam asked 3 years ago

What is the output of the following code?

def stringParser():

    while True:

        name = yield

        (fname, lname) = name.split()

        f.send(fname)

        f.send(lname)

def stringLength():

    while True:

        string = yield

        print("Length of '{}' : {}".format(string, len(string)))

f = stringLength(); next(f)

s = stringParser()

next(s)

s.send('Jack Black')

 
a. Length of ‘Jack’ : 4
b. Length of ‘Jack’ : 4
Length of ‘Black’ : 5
c. Results in Error
d. Length of ‘Jack Black’ : 10