Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Determine whether an integer is a palindrome. D o this without extra space. A palindrome integer is an integer x for which reverse(x) = x

Determine whether an integer is a palindrome. D o this without extra space.

A palindrome integer is an integer x for which reverse(x) = x where reverse(x) is x with its digit reversed.

Negative numbers are not palindromic.

Example :

Input : 12121

Output : True

Input : 123

Output : False

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

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

>>> import collections

>>> a=dict()

>>> a=collections.defaultdict(int)

>>> a[1]

a) 1

b) 0

c) An exception is thrown

d) ' '

2. Which of the following returns a string that represents the present working directory?

a) os.getcwd()

b) os.cwd()

c) os.getpwd()

d) os.pwd()

3. Which of the statements about dictionary values if false?

a) More than one key can have the same value

b) The values of the dictionary can be accessed as dict[key]

c) Values of a dictionary must be unique

d) Values of a dictionary can be a mixture of letters and numbers

4. Which of the following cannot be returned by random.randrange(4)?

a) 0

b) 3

c) 2.3

d) none of the mentioned

5. What is the result of sum([.1 for i in range(20)])?

a) 2.0

b) 20

c) 2

d) 2.0000000000000004

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

class A:

def str(self):

return '1'

class B(A):

def init(self):

super().init()

class C(B):

def init(self):

super().init()

def main():

obj1 = B()

obj2 = A()

obj3 = C()

print(obj1, obj2,obj3)

main()

a) 1 1 1

b) 1 2 3

c) '1' '1' '1'

d) An exception is thrown

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

import turtle

t=turtle.Pen()

for i in range(1,4):

t.forward(60)

t.left(90)

a) Rectangle

b) Trapezium

c) Triangle

d) Square

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

x = [12, 34]

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

a) 4

b) 5

c) 6

d) error

9. Which of the codes shown below results in a match?

a) re.match('George(?=Washington)', 'George Washington')

b) re.match('George(?=Washington)', 'George')

c) re.match('George(?=Washington)', 'GeorgeWashington')

d) re.match('George(?=Washington)', 'Georgewashington')

10. Which of the following statements is true?

a) The new() method automatically invokes the init method

b) The init method is defined in the object class

c) The eq(other) method is defined in the object class

d) The __repr() method is defined in the object class

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

def sayHello():

print('Hello World!')

sayHello()

sayHello()

a)

Hello World!

Hello World!

b)

'Hello World!'

'Hello World!'

c)

Hello

Hello

advertisement

d) None of the mentioned

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

a) True

b) False

13. Which of the following mode will refer to binary data?

a) r

b) w

c) +

d) b

14. Which function overloads the + operator?

a) add()

b) plus()

c) sum()

d) none of the mentioned

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

x = [[0], [1]]

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

a) 2

b) 3

c) 7

d) 8

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

>>>import collections

>>> b=collections.Counter([2,2,3,4,4,4])

>>> b.most_common(1)

a) Counter({4: 3, 2: 2, 3: 1})

b) {3:1}

c) {4:3}

d) [(4, 3)]

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

class A():

def disp(self):

print("A disp()")

class B(A):

pass

obj = B()

obj.disp()

a) Invalid syntax for inheritance

b) Error because when object is created, argument must be passed

c) Nothing is printed

d) A disp()

18. Which of these about a dictionary is false?

a) The values of a dictionary can be accessed using keys

b) The keys of a dictionary can be accessed using values

c) Dictionaries aren't ordered

d) Dictionaries are mutable

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

fo = open("foo.txt", "wb")

print "Name of the file: ", fo.name

fo.flush()

fo.close()

a) Compilation Error

b) Runtime Error

c) No Output

d) Flushes the file when closing them

20. The output of the following two Python codes are the same.

CODE 1

>>> re.split(r'(a)(t)', 'The night sky')

CODE 2

>>> re.split(r'\s+', 'The night sky')

a) True

b) False

21. Correct syntax of file.readlines() is?

a) fileObject.readlines( sizehint );

b) fileObject.readlines();

c) fileObject.readlines(sequence)

d) none of the mentioned

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

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