0% found this document useful (0 votes)
57 views9 pages

String Manipulation Type B Quesitons

Uploaded by

Himanshu Tonk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views9 pages

String Manipulation Type B Quesitons

Uploaded by

Himanshu Tonk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

String Manipulation

Type B: Application Based Questions

Question 1. What is the result of the following expression?


(a)

Answer:

(b)

Answer:

(c)
Answer:

(d)

Answer:

(e)

Answer

Question 2: What will be the output produced by following code


fragments?
(a)
Answer

(b)

Answer

(c)

Answer:
Question 3: Carefully go through the code given below and answer
the questions based on it:

(i) Given the input integer 3, what output is produced by Line 1?


This is a test
This is a
is a test
is a
None of these
Answer
Option 1: This is a test

(ii) Given the input integer 3, what output is produced by Line 2?


This is a test
s is a t
is a test
is a
None of these
Answer
Option 2: s is a t

(iii) Given the input integer 2, what output is produced by Line 3?


0
1
2
3
None of these
Answer
Option 5: None of these

(iv) Given the input integer 2, what output is produced by Line 4?


False
True
0
1
None of these
Answer
Option 2: True

Question 4: Carefully go through the code given below and answer


the questions based on it:
(i) Given the input integer 4, what output is produced by Line 2?
abcdefg
aabbccddeeffgg
abcdeefgh
ghi
None of these
Answer
Option 3: abcdeefgh

(ii) Given the input integer 4, what output is produced by Line 3?


abcdefg
aabbccddeeffgg
abcdeefgh
ghi
None of these
Answer
Option 4: ghi

(iii) Given the input integer 3, what output is produced by Line 4?


0
1
2
3
None of these
Answer
Option 5: None of these

(iv) Given the input integer 3, what output is produced by Line 5?


0
1
2
3
None of these
Answer
Option 4: 3

(v) Which statement is equivalent to the statement found in Line 1?


testStr = testStr[2:0]
testStr = testStr[2:-1]
testStr = testStr[2:-2]
testStr = testStr - 2
None of these
Answer
Option 5: None of these

Q5. Skipped
Q6. Skipped
Q7. Find the output if input string is “Test”.
(a)

Answer: Output:

(b)
Answer: The program gives an error at line RS = ch + 2 + RS. The
operands to + are a mix of string and integer which is not allowed in
Python.

Q8. Find the errors. Find the line numbers causing errors.
(a)

Ans. The error is in line 2. Length of string S is 9 so its indexes range


for 0 to 8. S[9] is causing error as we are trying to access out of
bound index.

(b)

Ans. The error is in line 3. Length of string S is 9 so its forward


indexes range for 0 to 8 and backwards indexes range from -1 to -9.
S[10] and S[-10] are trying to access out of bound indexes.

Question 9: What is the output produced?


(i) >>> "whenever" .find("never")
(ii) >>> "whenever" .find("what")
Answer:
(i) 3
The starting index of substring "never" in "whenever" is 3.
(ii) -1
Substring "what" is not present in "whenever".

Question 10: What is the output produced?


(i) >>> "-".join(['123','365','1319'])
(ii) >>> " ".join(['Python', 'is', 'fun'])
Answer:
(i) '123-365-1319'
(ii) 'Python is fun'

Question 11: Given a string S, write expressions to print


a. First five characters of S
b. Ninth character of S
c. Reversed S
d. Alternate characters from reversed S
Answer
a. print(S[:5])
b. print(S[8])
c. for a in range(-1, (-len(S) - 1), -1) :
print(S[a], end = '')
d. for a in range(-1, (-len(S) - 1), -2) :
print(S[a], end = '')

You might also like