Question: Q: Given an array of integers, sort the array into a wave like array and return it, In other words, arrange the elements into a

Q:

Given an array of integers, sort the array into a wave like array and return it,

In other words, arrange the elements into a sequence such that a1 >= a2 <= a3 >= a4 <= a5.....

Example

Given [1, 2, 3, 4]

One possible answer : [2, 1, 4, 3]

Another possible answer : [4, 1, 3, 2]

Python code for above cp question and mcq questions explanation is must. code will be tested on large test cases

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

import random

random.choice([10.4, 56.99, 76])

a) Error

b) Either 10.4, 56.99 or 76

c) Any number other than 10.4, 56.99 and 76

d) 56.99 only

2. What will be the output of print(math.copysign(3, -1))?

a) 1

b) 1.0

c) -3

d) -3.0

3. What is the default base used when math.log(x) is found?

a) e

b) 10

c) 2

d) none of the mentioned

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

x = [[0], [1]]

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

a) ('[0] [1]',)

b) ('01',)

c) [0] [1]

d) 01

5. Identify the type of error in the following Python codes?

Print("Good Morning")

print("Good night)

a) Syntax, Syntax

b) Semantic, Syntax

c) Semantic, Semantic

d) Syntax, Semantic

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

a={}

a[2]=1

a[1]=[2,3,4]

print(a[1][1])

a) [2,3,4]

b) 3

c) 2

d) An exception is thrown

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

d = {"john":40, "peter":45}

d["john"]

a) 40

b) 45

c) "john"

d) "peter"

8. Which function overloads the + operator?

a) add()

b) plus()

c) sum()

d) none of the mentioned

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

x = 'abcd'

print(list(map([], x)))

a) ['a', 'b', 'c', 'd']

b) ['abcd']

c) [['a'], ['b'], ['c'], ['d']]

d) none of the mentioned

10. Which of the following functions creates a Python object?

a) re.compile(str)

b) re.assemble(str)

c) re.regex(str)

d) re.create(str)

11. _______________________ exceptions are raised as a result of an error in opening a particular file.

a) ValueError

b) TypeError

c) ImportError

d) IOError

12. Which of the following functions will not result in an error when no arguments are passed to it?

a) min()

b) divmod()

c) all()

d) float()

13. _____ is used to createan object.

a) class

b) constructor

c) User-defined functions

d) In-built functions

14. Which of the following functions results in case insensitive matching?

a) re.A

b) re.U

c) re.I

d) re.X

15. Lambda is a statement.

a) True

b) False

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

class fruits:

def init(self, price):

self.price = price

obj=fruits(50)

obj.quantity=10

obj.bags=2

print(obj.quantity+len(obj.dict))

a) 12

b) 52

c) 13

d) 60

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

>>> class demo():

def repr(self):

return 'repr built-in function called'

def str(self):

return 'strbuilt-in function called'

>>> s=demo()

>>> print(s)

a) str called

b) repr called

c) Error

d) Nothing is printed

18. Which module in Python supports regular expressions?

a) re

b) regex

c) pyregex

d) none of the mentioned

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

import random

random.choice(2,3,4)

a) An integer other than 2, 3 and 4

b) Either 2, 3 or 4

c) Error

d) 3 only

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

a=10

globals()['a']=25

print(a)

a) 10

b) 25

c) Junk value

d) Error

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

def to_upper(k):

return k.upper()

x = ['ab', 'cd']

print(list(map(to_upper, x)))

a) ['AB', 'CD']

b) ['ab', 'cd']

c) none of the mentioned

d) error

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

x=12

def f1(a,b=x):

print(a,b)

x=15

f1(4)

a) Error

b) 12 4

c) 4 12

d) 4 15

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

class Demo:

def init(self):

self.a = 1

self.b = 1

def display(self):

return self.__b

obj = Demo()

print(obj.a)

a) The program has an error because there isn't any function to return self.a

b) The program has an error because b is private and display(self) is returning a private member

c) The program runs fine and 1 is printed

d) The program has an error as you can't name a class member using __b

24. Is the following Python code correct?

>>> class A:

def __init(self,b):

self.b=b

def display(self):

print(self.b)

>>> obj=A("Hello")

>>> del obj

a) True

b) False

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

import re

re.ASCII

a) 8

b) 32

c) 64

d) 256

26. How do you change the file position to an offset value from the start?

a) fp.seek(offset, 0)

b) fp.seek(offset, 1)

c) fp.seek(offset, 2)

d) none of the mentioned

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

def getMonth(m):

if m<1 or m>12:

raise ValueError("Invalid")

print(m)

getMonth(6)

a) ValueError

b) Invalid

c) 6

d) ValueError("Invalid")

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

>>> class demo():

def repr(self):

return 'repr built-in function called'

def str(self):

return 'str built-in function called'

>>> s=demo()

>>> print(s)

a) Error

b) Nothing is printed

c) str called

d) repr called

29. Which of the following is not a valid namespace?

a) Global namespace

b) Public namespace

c) Built-in namespace

d) Local namespace

30. What does os.name contain?

a) the name of the operating system dependent module imported

b) the address of the module os

c) error, it should've been os.name()

d) none of the mentioned

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!