Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer all the questions with proper explanation for each 1. What is the biggest reason for the use of polymorphism? a) It allows the programmer

Answer all the questions with proper explanation for each

1. What is the biggest reason for the use of polymorphism?

a) It allows the programmer to think at a more abstract level

b) There is less program code to write

c) The program will have a more elegant design and will be easier to maintain and update

d) Program code takes up less space

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

a = {}

a[1] = 1

a['1'] = 2

a[1.0]=4

count = 0

for i in a:

count += a[i]

print(count)

a) An exception is thrown

b) 3

c) 6

d) 2

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

class A:

def __init__(self):

self.__i = 1

self.j = 5

def display(self):

print(self.__i, self.j)

class B(A):

def __init__(self):

super().__init__()

self.__i = 2

self.j = 7

c = B()

c.display()

a) 2 7

b) 1 5

c) 1 7

d) 2 5

4. If a function doesn't have a return statement, which of the following does the function return?

a) int

b) null

c) None

d) An exception is thrown without the return statement

5. The value returned when we use the function isoweekday() is __ and that for the function weekday() is ____ if the system date is 19th June, 2017 (Monday).

a) 0,0

b) 0,1

c) 1,0

d) 1,1

6. Which function is used to writ. all the characters?

a) write()

b) writecharacters()

c) writeall()

d) writechar()

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

import re

re.ASCII

a) 8

b) 32

c) 64

d) 256

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

count={}

count[(1,2,4)] = 5

count[(4,2,1)] = 7

count[(1,2)] = 6

count[(4,2,1)] = 2

tot = 0

for i in count:

tot=tot+count[i]

print(len(count)+tot)

a) 25

b) 17

c) 16

d) Tuples can't be made keys of a dictionary

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

elements = [0, 1, 2]

def incr(x):

return x+1

print(list(map(elements, incr)))

a) [1, 2, 3]

b) [0, 1, 2]

c) error

d) none of the mentioned

10. What will be the output of the following Python code, if the time module has already been imported?

def num(m):

t1 = time.time()

for i in range(0,m):

print(i)

t2 = time.time()

print(str(t2-t1))

num(3)

a)

1

2

3

The time taken for the execution of the code

b)

3

The time taken for the execution of the code

c)

1

2

3

UTC time

d)

3

UTC time

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

import sys

sys.argv[0]

a) Junk value

b) ' '

c) No output

d) Error

12. What type of inheritance is illustrated in the following Python code?

class A():

pass

class B():

pass

class C(A,B):

pass

a) Multi-level inheritance

b) Multiple inheritance

c) Hierarchical inheritance

d) Single-level inheritance

13. The special character \B matches the empty string, but only when it is _________

a) at the beginning or end of a word

b) not at the beginning or end of a word

c) at the beginning of the word

d) at the end of the word

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

re.compile('hello', re.X)

a) ['h', 'e', 'l', 'l', 'o']

b) re.compile('hello', re.VERBOSE)

c) Error

d) Junk value

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

a) 1

b) 1.0

c) -3

d) -3.0

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

class A:

def __init__(self):

self.multiply(15)

def multiply(self, i):

self.i = 4 * i;

class B(A):

def __init__(self):

super().__init__()

print(self.i)

def multiply(self, i):

self.i = 2 * i;

obj = B()

a) 15

b) 30

c) An exception is thrown

d) 60

17. What is the pickling?

a) It is used for object serialization

b) It is used for object deserialization

c) None of the mentioned

d) All of the mentioned

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

total={}

def insert(items):

if items in total:

total[items] += 1

else:

total[items] = 1

insert('Apple')

insert('Ball')

insert('Apple')

print (len(total))

a) 3

b) 1

c) 2

d) 0

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

import turtle

t=turtle.Pen()

for i in range(0,6):

t.forward(100)

t.left(60)

a) Hexagon

b) Octagon

c) Pentagon

d) Heptagon

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

l=[-2, 4]

m=map(lambda x:x*2, l)

print(m)

a) [-4, 16]

b) Address of m

c) Error

d)

-4

16

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

x = [12, 34]

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

a) 4

b) 5

c) 6

d) error

22. What is the order of namespaces in which Python looks for an identifier?

a) Python first searches the global namespace, then the local namespace and finally the built-in namespace

b) Python first searches the local namespace, then the global namespace and finally the built-in namespace

c) Python first searches the built-in namespace, then the global namespace and finally the local namespace

d) Python first searches the built-in namespace, then the local namespace and finally the global namespace

23. 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")

24. 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'

25. What will be the output of the following Python code if the system date is 18th June, 2017 (Sunday)?

import datetime

tday=datetime.date.today()

print(tday)

a) 18-06-2017

b) 06-18-2017

c) 2017-06-18

d) Error

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. How can education be used as a signal in the job market?

Answered: 1 week ago