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]

Please doanswer all the questions with proper explanation, I need code for above cp question and it should pass all large and corner test cases, I need explanation for each mcq below. Please don't copy

1. Lambda contains block of statements.

a) True

b) False

2. To open a file c:\scores.txt for appending data, we use ____________

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

b) outfile = open("c:\\scores.txt", "rw")

c) outfile = open(file = "c:\scores.txt", "w")

d) outfile = open(file = "c:\\scores.txt", "w")

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

4. Which of the following can be used to createa symbolic link?

a) os.symlink()

b) os.symb_link()

c) os.symblin()

d) os.ln()

5. What happens if the base condition isn't defined in recursive programs?

a) Program gets into an infinite loop

b) Program runs once

c) Program runs n number of times where n is the argument given to the function

d) An exception is thrown

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

a) infile.read(2)

b) infile.read()

c) infile.readline()

d) infile.readlines()

7. Which of the following is the most suitable definition for encapsulation?

a) Ability of a class to derive members of another class as a part of its own definition

b) Means of bundling instance variables and methods in order to restrict access to certain class members

c) Focuses on variables and passing of variables to functions

d) Allows for implementation of elegant software that is well designed and easily modified

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

lst = [1, 2, 3]

lst[3]

a) NameError

b) ValueError

c) IndexError

d) TypeError

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

def power(x, y=2):

r = 1

for i in range(y):

r = r * x

return r

print power(3)

print power(3, 3)

a)

212

32

b)

9

27

c)

567

98

d) None of the mentioned

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

random.randrange(0,91,5)

a) 10

b) 18

c) 79

d) 95

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

float('-infinity')

float('inf')

a)

-inf

inf

b)

-infinity

inf

c)

Error

Error

d)

Error

Junk value

12. What is tail recursion?

a) A recursive function that has two base cases

b) A function where the recursive functions leads to an infinite loop

c) A recursive function where the function doesn't return anything and just prints the values

d) A function where the recursive call is the last thing executed by the function

13. Which of the following is not an exception handling keyword in Python?

a) try

b) except

c) accept

d) finally

14. What will be the output of the following Python code if the system date is 21st June, 2017 (Wednesday)?

tday=datetime.date.today()

print(tday.isoweekday())

a) Wed

b) Wednesday

c) 2

d) 3

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

>>> a={i: i*i for i in range(6)}

>>> a

a) Dictionary comprehension doesn't exist

b) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36}

c) {0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25}

d) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

16. Which of the following lines of code will not show a match?

a) >>> re.match('ab*', 'a')

b) >>> re.match('ab*', 'ab')

c) >>> re.match('ab*', 'abb')

d) >>> re.match('ab*', 'ba')

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

def f(x):

for i in range(5):

yield i

g=f(8)

print(list(g))

a) [0, 1, 2, 3, 4]

b) [1, 2, 3, 4, 5, 6, 7, 8]

c) [1, 2, 3, 4, 5]

d) [0, 1, 2, 3, 4, 5, 6, 7]

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

import turtle

t=turtle.Pen()

t.backward(100)

t.penup()

t.right(45)

t.isdown()

a) True

b) False

c) Yes

d) No

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

all([2,4,0,6])

a) Error

b) True

c) False

d) 0

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

sentence = 'horses are fast'

regex = re.compile('(?P\w+) (?P\w+) (?P\w+)')

matched = re.search(regex, sentence)

print(matched.group(2))

a) {'animal': 'horses', 'verb': 'are', 'adjective': 'fast'}

b) ('horses', 'are', 'fast')

c) 'horses are fast'

d) 'are'

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

def a(b):

b = b + [5]

c = [1, 2, 3, 4]

a(c)

print(len(c))

a) 4

b) 5

c) 1

d) An exception is thrown

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

l1=[10, 20, 30, [40]]

l2=copy.deepcopy(l1)

l1[3][0]=90

l1

l2

a)

[10, 20, 30, [40]]

[10, 20, 30, 90]

b) Error

c)

[10, 20, 30 [90]]

[10, 20, 30, [40]]

d)

[10, 20, 30, [40]]

[10, 20, 30, [90]]

23. The output of the following codes are the same.

[x**2 for x in range(10)]

list(map((lambda x:x**2), range(10)))

a) True

b) False

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

def f1(a,b=[]):

b.append(a)

return b

print(f1(2,[3,4]))

a) [3,2,4]

b) [2,3,4]

c) Error

d) [3,4,2]

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