ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from math import gcd print(gcd(0, 5), gcd(-4, 6), gcd(0, 0))
- A. 5 2 None
- B. 5 2 0
- C. 5 3 0
- D. 0 2 0
Correct answer: B. 5 2 0
gcd(0, n) is |n|. math.gcd returns a nonnegative result even for negative arguments, so gcd(-4, 6) is 2. gcd(0, 0) is 0.
More Python Programming questions
- What is printed? python x = 12 x //= 5 y = 12 y /= 5 print(x, y, type(x).name, type(y).name)
- What is printed? python import itertools print(list(itertools.islice(itertools.cycle('ab'), 5)), list(itertools.repeat(7, 2)))
- What is printed? python def f(): yield 1 yield 2 print(sum(f()), max(f()), list(zip(f(), f())))
- What is printed? python s = 'a-b-c' print(s.split('-', 1), s.rsplit('-', 1)[-1], s.partition('-')[2])
- What is printed? python print(divmod(-1, 10), divmod(1, -10), -1 % 10)
- What is printed? python words = ['hi', 'there', 'hey'] print(max(words), min(words, key=len), sorted(words, key=lambda w: (len(w), w)))