Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q: Coding Question Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals

Q:

Coding Question Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).

You may assume that the intervals were initially sorted according to their start times.

Example 1:

Given intervals [1,3],[6,9] insert and merge [2,5] would result in [1,5],[6,9].

Example 2:

Given [1,2],[3,5],[6,7],[8,10],[12,16], insert and merge [4,9] would result in [1,2],[3,10],[12,16].

This is because the new interval [4,9] overlaps with [3,5],[6,7],[8,10].

Make sure the returned intervals are also sorted.

Python code and mcq explanation needed. Please don't copy from anywhere

1. How are required arguments specified in the function heading?

a) identifier followed by an equal to sign and the default value

b) identifier followed by the default value within backticks (")

c) identifier followed by the default value within square brackets ([])

d) identifier

2. What will be the output of the following Python code?

y = 6

z = lambda x: x * y

print z(8)

a) 48

b) 14

c) 64

d) None of the mentioned

3. What is math.factorial(4.0)?

a) 24

b) 1

c) error

d) none of the mentioned

4. What will be the output of the following Python code?

class stud:

def init(self, roll_no, grade):

self.roll_no = roll_no

self.grade = grade

def display (self):

print("Roll no : ", self.roll_no,", Grade: ", self.grade)

stud1 = stud(34, 'S')

stud1.age=7

print(hasattr(stud1, 'age'))

a) Error as age isn't defined

b) True

c) False

d) 7

5. How are keyword arguments specified in the function heading?

a) one-star followed by a valid identifier

b) one underscore followed by a valid identifier

c) two stars followed by a valid identifier

d) two underscores followed by a valid identifier

6. What does single-level inheritance mean?

a) A subclass derives from a class which in turn derives from another class

b) A single superclass inherits from multiple subclasses

c) A single subclass derives from a single superclass

d) Multiple base classes inherit a single derived class

7. To read two characters from a file object infile, we use ____________

a) infile.read(2)

b) infile.read()

c) infile.readline()

d) infile.readlines()

8. The output of the function len(sys.argv) is ____________

a) Error

b) 1

c) 0

d) Junk value

9. Is the following Python code valid?

try:

# Do something

except:

# Do something

finally:

# Do something

a) no, there is no such thing as finally

b) no, finally cannot be used with except

c) no, finally must come before except

d) yes

10. What will be the output of the following Python code?

class Demo:

def init(self):

pass

def test(self):

print(name)

obj = Demo()

obj.test()

a) Exception is thrown

b) main

c) Demo

d) test

11. What will be the output of the following Python code?

sentence = 'we are humans'

matched = re.match(r'(.*) (.*?) (.*)', sentence)

print(matched.group())

a) ('we', 'are', 'humans')

b) (we, are, humans)

c) ('we', 'humans')

d) 'we are humans'

12. _____ represents an entity in the real world with its identity and behaviour.

a) A method

b) An object

c) A class

d) An operator

13. What does the function re.search do?

a) matches a pattern at the start of the string

b) matches a pattern at any position in the string

c) such a function does not exist

d) none of the mentioned

14. What will be the output of the following Python code?

import sys

eval(sys.stdin.readline())

Computer

a) Error

b) 'Computer '

c) Computer8

d) Computer

15. To open a file c:\scores.txt for reading, we use _____________

a) infile = open("c:\scores.txt", "r")

b) infile = open("c:\\scores.txt", "r")

c) infile = open(file = "c:\scores.txt", "r")

d) infile = open(file = "c:\\scores.txt", "r")

16. What will be the output of the following Python code snippet?

numbers = {}

letters = {}

comb = {}

numbers[1] = 56

numbers[3] = 7

letters[4] = 'B'

comb['Numbers'] = numbers

comb['Letters'] = letters

print(comb)

a) Error, dictionary in a dictionary can't exist

b) 'Numbers': {1: 56, 3: 7}

c) {'Numbers': {1: 56}, 'Letters': {4: 'B'}}

d) {'Numbers': {1: 56, 3: 7}, 'Letters': {4: 'B'}}

17. What will be the output of the following Python functions?

float('1e-003')

float('2e+003')

a)

3.00

300

b)

0.001

2000.0

c)

0.001

200

d)

Error

2003

18. What will be the output of the following Python code?

def foo(k):

k = [1]

q = [0]

foo(q)

print(q)

a) [0]

b) [1]

c) [1, 0]

d) [0, 1]

19. Which of the following is equivalent to random.randint(3, 6)?

a) random.choice([3, 6])

b) random.randrange(3, 6)

c) 3 + random.randrange(3)

d) 3 + random.randrange(4)

20. Which function is called when the following Python code is executed?

f = foo()

format(f)

a) format()

b) format()

c) str()

d) str()

21. What will be the output of the following Python code?

x = [12, 34]

print(len(''.join(list(map(int, x)))))

a) 4

b) 2

c) error

d) none of the mentioned

22. If getstate() returns _______________ the setstate() module will not be called on pickling.

a) True value

b) False value

c) ValueError

d) OverflowError

23. What will be the output of the following Python code?

import turtle

t=turtle.Pen()

t.clear()

t.isvisible()

a) Yes

b) True

c) No

d) False

24. In top-down design every module is broken into same number of submodules.

a) True

b) False

25. What will be the output of the following Python code?

random.randrange(0,91,5)

a) 10

b) 18

c) 79

d) 95

26. Which of these is a private data field?

def Demo:

def init(self):

a = 1

self.__b = 1

self.__c = 1

d= 1

a) a

b) __b

c) __c

d) d

27. What will be the output of the following Python code?

x = [12.1, 34.0]

print(' '.join(list(map(str, x))))

a) 12 1 34 0

b) 12.1 34

c) 121 340

d) 12.1 34.0

28. What is the output of the function complex()?

a) 0j

b) 0+0j

c) 0

d) Error

29. What will be the output of the following Python code?

from math import factorial

print(math.factorial(5))

a) 120

b) Nothing is printed

c) Error, method factorial doesn't exist in math module

d) Error, the statement should be: print(factorial(5))

30. Pick the correct statement regarding pickle and marshal modules.

a) The pickle module supports primarily .pyc files whereas marshal module is used to sterilize Python objects

b) The pickle module keeps track of the objects that have already been sterilized whereas the marshal module does not dothis

c) The pickle module cannot be used to sterilize user defined classes and their instances whereas marshal module can be used to perform this task

d) The format of sterilization of the pickle module is not guaranteed to be supported across all versions of Python. The marshal module sterilization is compatible across all the versions of Python

31. Methods of a class that provide access to private members of the class are called as ______ and ______

a) getters/setters

b) repr/str

c) user-defined functions/in-built functions

d) init/del

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

11. What is a composite currency unit?

Answered: 1 week ago