Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The string PAYPALISHIRING is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

P.......A........H.......N

..A..P....L....S....I...I....G

....Y.........I........R

And then read line by line: PAHNAPLSIIGYIR

Write the code that will take a string and make this conversion given a number of rows:

string convert(string text, int nRows);

convert("PAYPALISHIRING", 3) should return "PAHNAPLSIIGYIR"

Example 2 :

ABCD, 2 can be written as

A....C

...B....D

and hence the answer would be ACBD.

Please note that python code for above question should pass large test cases, and all corner test cases, reasoning for below MCQs is also needed, please dont copy (unhelpful if copied or didn't answer all)

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

s1={3, 4}

s2={1, 2}

s3=set()

i=0

j=0

for i in s1:

for j in s2:

s3.add((i,j))

i+=1

j+=1

print(s3)

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

b) Error

c) {(4, 2), (3, 1), (4, 1), (5, 2)}

d) {(3, 1), (4, 2)}

2. The ____ function removes the first element of a set and the last element of a list.

a) remove

b) pop

c) discard

d) dispose

3. The difference between the functions discard and remove is that:

a) Discard removes the last element of the set whereas remove removes the first element of the set

b) Discard throws an error if the specified element is not present in the set whereas remove does not throw an error in case of absence of the specified element

c) Remove removes the last element of the set whereas discard removes the first element of the set

d) Remove throws an error if the specified element is not present in the set whereas discard does not throw an error in case of absence of the specified element

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

s1={1, 2, 3}

s2={3, 4, 5, 6}

s1.difference(s2)

s2.difference(s1)

a)

{1, 2}

{4, 5, 6}

b)

{1, 2}

{1, 2}

c)

{4, 5, 6}

{1, 2}

d)

{4, 5, 6}

{4, 5, 6}

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

s1={1, 2, 3}

s2={4, 5, 6}

s1.isdisjoint(s2)

s2.isdisjoint(s1)

a)

True

False

b)

False

True

c)

True

True

d)

False

False

6. If we have two sets, s1 and s2, and we want to check if all the elements of s1 are present in s2 or not, we can use the function:

a) s2.issubset(s1)

b) s2.issuperset(s1)

c) s1.issuperset(s2)

d) s1.isset(s2)

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

s1={1, 2, 3, 8}

s2={3, 4, 5, 6}

s1|s2

s1.union(s2)

a)

{3}

{1, 2, 3, 4, 5, 6, 8}

b)

{1, 2, 4, 5, 6, 8}

{1, 2, 4, 5, 6, 8}

c)

{3}

{3}

d)

{1, 2, 3, 4, 5, 6, 8}

{1, 2, 3, 4, 5, 6, 8}

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

a=set('abc')

b=set('def')

b.intersection_update(a)

a

b

a)

set()

('e', 'd', 'f'}

b)

{}

{}

c)

{'b', 'c', 'a'}

set()

d)

set()

set()

9. What will be the output of the following Python code, if s1= {1, 2, 3}?

s1.issubset(s1)

a) True

b) Error

c) No output

d) False

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

x=set('abcde')

y=set('xyzbd')

x.difference_update(y)

x

y

a)

{'a', 'b', 'c', 'd', 'e'}

{'x', 'y', 'z'}

b)

{'a', 'c', 'e'}

{'x', 'y', 'z', 'b', 'd'}

c)

{'b', 'd'}

{'b', 'd'}

d)

{'a', 'c', 'e'}

{'x', 'y', 'z'}

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

What are some challenges facing Louis Vuitton today?

Answered: 1 week ago