ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(divmod(-1, 10), divmod(1, -10), -1 % 10)
- A. (-1, 9) (-1, 8) 9
- B. (0, 9) (0, -9) -1
- C. (-1, 9) (-1, -9) 9
- D. (0, -1) (0, 1) 9
Correct answer: C. (-1, 9) (-1, -9) 9
Floor division gives -1 for -1 // 10 with remainder 9. For 1 // -10 the quotient is -1 and the remainder is 1 + (-10) = -9. -1 % 10 is 9.
More Python Programming questions
- What is printed? python words = ['hi', 'there', 'hey'] print(max(words), min(words, key=len), sorted(words, key=lambda w: (len(w), w)))
- What is printed? python print(pow(0, 0), 0 0 == 1, pow(2, -2, 5), pow(0, 0, 5))
- What is printed? python import math print(0.0 == -0.0, 1 / float('-inf'), 2 -1074 / 2 == 0, math.copysign(0.0, -1))
- What is printed? python try: print(int('')) except ValueError: print('empty') try: print(0.0 / 0) except ZeroDivisionError: print('zero')
- What is printed? python import math try: print(math.sqrt(-1)) except ValueError: print('domain') print(float('nan') 0, math.pow(0, 0))
- What is printed? python print('{:e}'.format(1234.5), '{:.3g}'.format(1234567), '{:g}'.format(0.0001), '{:g}'.format(0.00001))