ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
a = 'Python' print(a[::-1][1:4], a[-2:] + a[:2], a.upper()[::2])
- A. oht Pyon PTO
- B. oht onPy PYT
- C. hto onPy PTO
- D. oht onPy PTO
Correct answer: D. oht onPy PTO
a[::-1] is 'nohtyP', and [1:4] of that is 'oht'. a[-2:] + a[:2] is 'on' + 'Py'. upper() gives PYTHON and [::2] takes indices 0, 2, 4, which are P, T and O.
More Python Programming questions
- What is printed? python n = 10 6 s = 0 i = 1 while i <= n: s += n // i i = 10 print(s)
- What is printed? python def matmul(A, B, m): return [[sum(A[i][k] B[k][j] for k in range(2)) % m for j in range(2)] for i in range(2)] def…
- What is printed? python n = 12 print(n & 1 == 0, (n & 1) == 0, n & n - 1 == 0, 8 & 7 == 0)
- What is printed on the first line? python print(pow(2, -1, 5), pow(3, -1, 7), pow(2, -3, 9)) try: print(pow(2, -1, 4)) except ValueError…
- What is printed? python import math print(math.comb(100, 50) % 1000, len(str(math.comb(100, 50))), math.perm(5, 2), math.comb(5, 7))
- What is printed? python import math print(math.floor(-0.5), math.ceil(-0.5), math.trunc(-0.5), math.floor(2.999999999999999999))