ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(hex(255), hex(-255), oct(-8), bin(0), int('-ff', 16), int('0xFF', 0))- A. 0xff -0xff -0o10 0b0 -255 255
- B. 0xff -0xff -0o8 0b0 -255 255
- C. 0xff -0xff -0o10 0b1 -255 255
- D. 0xff -0xff -0o10 0b0 -255 254
Correct answer: A. 0xff -0xff -0o10 0b0 -255 255
hex, oct and bin keep the sign in front of the digits rather than printing two's complement, and int with base 16 accepts a leading minus sign. Base 0 reads the 0x prefix and gives 255.
More Python Programming questions
- What is printed? python print(int('8' 3) % 7, int('8' 3, 16) % 7, pow(10, 3, 7), 888 % 7)
- What is printed? python print(0.1 0.1, 0.1 0.1 == 0.01, round(0.1 0.1, 2) == 0.01, 10 0.1 0.1 10 == 1)
- What is printed? python print(len(str(777)), 777 % 1000, str(777)[-3:], int(str(777)[:3]))
- What is printed? python def rpn(tokens): st = [] for t in tokens: if t in ('+', '-', '', '/'): b = st.pop() a = st.pop() if t == '+'…
- What is printed? python def ceildiv(a, b): return -(-a // b) print(ceildiv(7, 2), ceildiv(-7, 2), ceildiv(6, 3), ceildiv(1, 5))
- What is printed? python def atmost(a, k): l = s = c = 0 for r, x in enumerate(a): s += x while s > k: s -= a[l] l += 1 c += r - l + 1…