ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
print(1_000 == 1000, 0.1 + 0.7, 7 / 2 == 7 // 2 + 0.5, 2 ** 0.5 ** 2, (-8) ** (1 / 3) == -2)
- A. True 0.8 True 2.0 False
- B. True 0.7999999999999999 True 2.0 True
- C. False 0.8 True 1.189207115002721 False
- D. True 0.7999999999999999 True 1.189207115002721 False
Correct answer: D. True 0.7999999999999999 True 1.189207115002721 False
Underscores in literals are ignored. 0.1 + 0.7 shows binary error. ** is right-associative: 2 ** (0.5 ** 2) = 2 ** 0.25. A negative base with a fractional exponent yields a complex number, not -2.
More Python Programming questions
- What is printed? python s = "racecar" print(s.index("c"), s.rindex("c"), s.find("c", 3), s[::-1] is s, s.count("a", 2))
- What is printed? python import sys print(type(10 20).name, 10 20 // 3 % 10, len(str(2 100)), (2 64) - 1 == 0xFFFFFFFFFFFFFFFF)
- What is printed? python x = [1, 2, 3] print(x 2, [x] 2 == [[1, 2, 3], [1, 2, 3]], x + [4] is x, [] == False, not [])
- What is printed? python t = 1, 2, u = (3) v = () w = (4,) 0 print(type(t).name, len(t), type(u).name, v == w, (1, 2) < (1, 2, -1))
- What is printed? python class Err(Exception): def init(self, code): super().init(f"code {code}") self.code = code try: try: raise Err(7)…
- What is printed? python def check(v): assert v > 0, f"bad {v}" return v try: check(-1) except AssertionError as e: print("AE", e, end=" ")…