Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 and mcq explanation needed. Please don't copy from anywhere

1. Which of the following will never be displayed on executing print(random.choice({0: 1, 2: 3}))?

a) 0

b) 1

c) KeyError: 1

d) none of the mentioned

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

x = ['ab', 'cd']

print(len(list(map(list, x))))

a) 2

b) 4

c) error

d) none of the mentioned

3. 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

4. Method issubclass() checks if a class is a subclass of another class.

a) True

b) False

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

import turtle

t=turtle.Pen()

t.color(0,1,0)

t.begin_fill()

for i in range(0,4):

t.forward(100)

t.right(90)

a) A square filled in with the colour green

b) A square outlined with the colour green

c) Blank canvas

d) Error

6. What is Instantiation in terms of OOP terminology?

a) Deleting an instance of class

b) Modifying an instance of class

c) Copying an instance of class

d) Creating an instance of class

7. Which of the following is equivalent to random.randrange(3)?

a) range(3)

b) random.choice(range(0, 3))

c) random.shuffle(range(3))

d) random.select(range(3))

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

def f(x):

print("outer")

def f1(a):

print("inner")

print(a,x)

f(3)

f1(1)

a)

outer

error

b)

inner

error

c)

outer

inner

d) error

9. Which of the following functions does not accept any arguments?

a) position

b) fillcolor

c) goto

d) setheading()

10. 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

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

>>> a={"a":1,"b":2,"c":3}

>>> b=dict(zip(a.values(),a.keys()))

>>> b

a) {'a': 1, 'b': 2, 'c': 3}

b) An exception is thrown

c) {'a': 'b': 'c': }

d) {1: 'a', 2: 'b', 3: 'c'}

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

class Demo:

def init(self):

self.a = 1

self.__b = 1

def get(self):

return self.__b

obj = Demo()

obj.a=45

print(obj.a)

a) The program runs properly and prints 45

b) The program has an error because the value of members of a class can't be changed from outside the class

c) The program runs properly and prints 1

d) The program has an error because the value of members outside a class can only be changed as self.a=45

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

import datetime

d=datetime.date(2017,06,18)

print(d)

a) Error

b) 2017-06-18

c) 18-06-2017

d) 06-18-2017

14. Overriding means changing behaviour of methods of derived class methods in the base class.

a) True

b) False

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

random.seed(3)

random.randint(1,5)

2

random.seed(3)

random.randint(1,5)

a) 3

b) 2

c) Any integer between 1 and 5, including 1 and 5

d) Any integer between 1 and 5, excluding 1 and 5

16. An exception is ____________

a) an object

b) a special function

c) a standard module

d) a module

17. Which of the following data structures is returned by the functions globals() and locals()?

a) list

b) set

c) dictionary

d) tuple

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