ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
def g():
x = yield 1
yield x * 2
it = g()
print(next(it), it.send(5))- A. 1 10
- B. 1 2
- C. TypeError
- D. 1 None
Correct answer: A. 1 10
next(it) runs up to the first yield and returns 1. send(5) resumes the generator, makes that paused yield expression evaluate to 5 (so x = 5), and runs to the next yield, which produces 10.
More Python Programming questions
- What is printed? python calls = 0 def f(n): global calls calls += 1 return 1 if n <= 1 else f(n - 1) + f(n - 2) print(f(5), calls)
- What is printed? python import copy a = [[1, 2], [3]] b = copy.copy(a) c = copy.deepcopy(a) a[0].append(9) a.append([4]) print(len(b)…
- What is printed? python x = [1] 3 for i in range(3): x[i] = x[i - 1] + i print(x)
- What is printed? python x = "g" def outer(): x = "o" def inner(): global x x = "i" inner() return x print(outer(), x)
- What is printed? python s = " Py Thon " print(s.strip().lower().replace(" ", "").count("o"), s.split(" ").count(""))
- What is printed? python def f(x): try: r = 10 // x except ZeroDivisionError: return "Z" else: return r finally: print("F", end=" ")…