Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q: Thanks in advance!! Given a string, find the rank of the string amongst its permutations sorted lexicographically. Note that the characters might be repeated.

Q:

Thanks in advance!!

Given a string, find the rank of the string amongst its permutations sorted lexicographically.

Note that the characters might be repeated. If the characters are repeated, we need to look at the rank in unique permutations.

Look at the example for more details.

Example :

Input : 'aba'

Output : 2

The order permutations with letters 'a', 'a', and 'b' :

aab

aba

baa

The answer might not fit in an integer, so return your answer % 1000003

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?

x = 'abcd'

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

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

b) ['abcd']

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

d) none of the mentioned

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

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

a) r

b) w

c) +

d) b

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

f = None

for i in range (5):

with open("data.txt", "w") as f:

if i > 2:

break

print(f.closed)

a) True

b) False

c) None

d) Error

5. The function divmod(a,b), where both 'a' and 'b' are integers is evaluated as:

a) (a%b, a//b)

b) (a//b, a%b)

c) (a//b, a*b)

d) (a/b, a%b)

6. Read the following Python code carefully and point out the global variables?

y, z = 1, 2

def f():

global x

x = y+z

a) x

b) y and z

c) x, y and z

d) Neither x, nor y, nor z

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

len(["hello",2, 4, 6])

a) 4

b) 3

c) Error

d) 6

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

x=3

eval('x^2')

a) Error

b) 1

c) 9

d) 6

9. Syntax errors are also known as parsing errors.

a) True

b) False

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

x = ['ab', 'cd']

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

a) [2, 2]

b) 2

c) 4

d) none of the mentioned

11. Which module in the python standard library parses options received from the command line?

a) getopt

b) os

c) getarg

d) main

12. Which of the following is a feature of DocString?

a) Provide a convenient way of associating documentation with Python modules, functions, classes, and methods

b) All functions should have a docstring

c) Docstrings can be accessed by the doc attribute on objects

d) All of the mentioned

13. Which of the following functions clears the regular expression cache?

a) re.sub()

b) re.pos()

c) re.purge()

d) re.subn()

14. What is the range of values that random.random() can return?

a) [0.0, 1.0]

b) (0.0, 1.0]

c) (0.0, 1.0)

d) [0.0, 1.0)

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

16. Which of the statements about modules is false?

a) In the "from-import" form of import, identifiers beginning with two underscores are private and aren't imported

b) dir() built-in function monitors the items in the namespace of the main module

c) In the "from-import" form of import, all identifiers regardless of whether they are private or public are imported

d) When a module is loaded, a compiled version of the module with file extension .pyc is automatically produced

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

all(3,0,4.2)

a) True

b) False

c) Error

d) 0

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

w = re.compile('[A-Za-z]+')

w.findall('It will rain today')

a) 'It will rain today'

b) ('It will rain today')

c) ['It will rain today']

d) ['It', 'will', 'rain', 'today']

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

numbers = {}

letters = {}

comb = {}

numbers[1] = 56

numbers[3] = 7

letters[4] = 'B'

comb['Numbers'] = numbers

comb['Letters'] = letters

print(comb)

a) Error, dictionary in a dictionary can't exist

b) 'Numbers': {1: 56, 3: 7}

c) {'Numbers': {1: 56}, 'Letters': {4: 'B'}}

d) {'Numbers': {1: 56, 3: 7}, 'Letters': {4: 'B'}}

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

re.findall("hello world", "hello", 1)

a) ["hello"]

b) [ ]

c) hello

d) hello world

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

x = 1234

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

a) [1, 2, 3, 4]

b) [1234]

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

d) none of the mentioned

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

re.split(r'(a)(t)', 'Maths is a difficult subject')

a) ['M a t h s i s a d i f f i c u l t s u b j e c t']

b) ['Maths', 'is', 'a', 'difficult', 'subject']

c) 'Maths is a difficult subject'

d) ['M', 'a', 't', 'hs is a difficult subject']

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

x = ['ab', 'cd']

print(map(len, x))

a) ['ab', 'cd']

b) [2, 2]

c) ['2', '2']

d) none of the mentioned

24. Which of the following are the modes of both writing and reading in binary format in file?

a) wb+

b) w

c) wb

d) w+

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

re.sub('Y', 'X', 'AAAAAA', count=2)

a) 'YXAAAA'

b) ('YXAAAA')

c) ('AAAAAA')

d) 'AAAAAA'

26. What will be the output of the following Python function, assuming that the random module has already been imported?

random.uniform(3,4)

a) Error

b) Either 3 or 4

c) Any integer other than 3 and 4

d) Any decimal value between 3 and 4

27. What is the use of "w" in file handling?

a) Read

b) Write

c) Append

d) None of the mentioned

28. The number of lines drawn in each case, assuming that the turtle module has been imported:

Case 1:

for i in range(0,10):

turtle.forward(100)

turtle.left(90)

Case 2:

for i in range(1,10):

turtle.forward(100)

turtle.left(90)

a) 10, 9

b) 9, 10

c) 9, 9

d) 10, 10

29. What is returned by math.expm1(p)?

a) (math.ep) - 1

b) math.e(p - 1)

c) error

d) none of the mentioned

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

Unity From Zero To Proficiency Beginner A Step By Step Guide To Coding Your First Game

Authors: Patrick Felicia

1st Edition

1091872023, 978-1091872028

More Books

Students also viewed these Programming questions

Question

What is electric dipole explain with example

Answered: 1 week ago

Question

What is polarization? Describe it with examples.

Answered: 1 week ago