ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
n = 12345 print(n // 10 ** 3 % 10, n % 10 ** 3 // 100, str(n)[1], n // 1000 % 10 == int(str(n)[1]))
- A. 2 3 3 True
- B. 3 3 2 True
- C. 2 3 2 True
- D. 2 4 2 False
Correct answer: C. 2 3 2 True
Integer division and modulus can extract digits by position: n // 1000 % 10 is the thousands digit, 2. n % 1000 // 100 is the hundreds digit, 3. The string index gives the same digit as the arithmetic.
More Python Programming questions
- What is printed? python import math print(math.gcd(240 - 1, 220 - 1) == 220 - 1, math.lcm(12, 18) == 36, math.gcd(1030, 1020) == 1020)
- What is printed? python s = 'racecar level noon python' print([w for w in s.split() if w == w[::-1]], len([w for w in s.split() if w ==…
- What is printed? python s = 'aAbBcC' print(s.lower().count('a') + s.upper().count('A'), s.swapcase(), ''.join(c for c in s if c.islower()))
- What is printed? python s = '2024-06-01' y, m, d = map(int, s.split('-')) print(y + m + d, s.replace('-', '/'), '%02d/%02d/%04d' % (d, m…
- What is printed? python print('%d' % 1020, '%.3e' % (270), len('%d' % (2100)), '%x' % (270))
- What is printed? python print(int(float('9007199254740993')) == 9007199254740993, float('9007199254740993') == 9007199254740992.0…