ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = 5 print(x if x > 3 else 0 if x == 3 else -1, 2 ** -1, 7 % 3 ** 2)
- A. 5 0.5 7
- B. 5 0.5 1
- C. 5 0 7
- D. 5 0.5 3
Correct answer: A. 5 0.5 7
Conditional expressions nest to the right, and x = 5 satisfies the first test. ** binds tighter than %, so 3 ** 2 = 9 and 7 % 9 is 7. A negative exponent on an int gives a float, 0.5.
More Python Programming questions
- Which technique is the reliable fix for a recursive DFS on a path graph with n = 10^5 nodes in Python, which otherwise raises…
- What is printed? python import math print(math.floor(-2.5), math.ceil(-2.5), math.trunc(-2.5), int(-2.5))
- What is printed? python x = 'xyz' print(f'{x!r:>7}|{len(x):03d}|{x[::-1]:^5}|')
- What is printed? python from itertools import chain print(list(chain.fromiterable(['ab', 'c'])), ''.join(chain([['x'], ['y', 'z']])))
- What is printed? python print(repr("it's"), repr('say "hi"'), len('x41101'), len(r'n'))
- What is printed? python print(pow(3, -1, 8)) try: print(pow(4, -1, 8)) except ValueError: print('not invertible')