ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(round(3.14159, 3), round(12345, -2), round(0.5), round(1.5), round(2.5, 0))
- A. 3.141 12300 0 2 2
- B. 3.142 12345 0 2 2.0
- C. 3.142 12300 1 2 2
- D. 3.142 12300 0 2 2.0
Correct answer: D. 3.142 12300 0 2 2.0
round with a digits argument returns a float for a float input, and round with a negative digits argument on an int returns an int, here 12300. Ties go to the even neighbour, so 0.5 gives 0, 1.5 gives 2 and 2.5 gives 2.0.
More Python Programming questions
- What is printed? python a = [3, 1, 2] b = sorted(a, reverse=True)[:2] c = sorted(a)[-2:] print(b, c, sum(b) + sum(c))
- What is printed? python word = 'Level' print(word.lower() == word.lower()[::-1], word == word[::-1], word.casefold() == 'level')
- What is printed? python d = {} for w in ['b', 'a', 'b']: d[w] = d.get(w, 0) + 1 print(d, max(d, key=d.get), sorted(d.values()…
- Which is the time complexity of checking whether a string s of length n is a palindrome, using s == s[::-1]?
- What is printed? python values = [0, 1, 2, 3] print([v for v in values if v] == values[1:], any(values), all(values[1:]))
- What is printed? python import heapq nums = [7, 2, 9] heapq.heapify(nums) print(nums[0], heapq.nlargest(1, nums)[0], heapq.nsmallest(2…