Page 379 - Computer Science V2.0 Class 11
P. 379
if str1[k]>="A" and str1[k]<="S":
str2=str2+str1[k+1]
elif str1[k]>="0" and str1[k]<="9":
str2=str2+str1[k-1]
else:
str2=str2+"*"
k=k+1
print(str2)
8. Differentiate between find() and index() with respect to strings in Python.
9. Using built-in functions, write Python statements to do the following tasks on the string named "My String".
(i) To remove the trailing spaces from the string.
(ii) To capitalize the first character of every word in a string.
(iii) To check whether all characters of a string are in uppercase.
(iv) To display the words of the strings as elements of a list.
(v) To check display the index from where the substring String starts.
(vi) To convert the lowercase alphabets of a string to uppercase.
(vii) Reverse a string.
10. Write a program that accepts a string and a character and replaces each occurrence of the character with '*'.
11. Write a function that takes a string as an argument and returns the number of words in the string.
12. Write a function that counts the number of vowels in a string. (both uppercase and lowercase)
13. Write a program that reverse the characters of each word in a string.
14. Write a program that accepts a string and prints the following:
(i) Number of words beginning with a vowel
(ii) Number of 3-lettered words
(iii) Number of digits
15. Write a program that accepts a string and prints a string, replacing each lowercase alphabet in the input string with
uppercase and vice versa.
16. Extend the module stringFns.py to perform the following operations on strings without using built-in functions:
(i) Find the first occurrence of the substring subStr in the string s.
(ii) Find the last occurrence of the substring subStr in the string s.
(iii) Find the frequency of the substring subStr in the string s.
(iv) Find the number of consonants present in the given string s.
(v) Find the number of uppercase and lowercase letters in the given string s.
(vi) Find the most frequently occurring character in the string s.
(vii) Reverse every word in the given sentence s.
Assertion and Reasoning Based Questions
The following questions are assertion(A) and reasoning(R) based. Mark the correct choice as
a. Both A and R are true and R is the correct explanation of A
b. Both A and R are true and R is not the correct explanation of A
c. A is true but R is false
d. A is false but R is true
1. Assertion(R): Python allows a string literal to span multiple lines.
Reasoning(R): A multiline string is enclosed between triple single quotes or triple double quotes.
2. Assertion(A): First character in a string is at index 0, the next is at index 1, and so on.
Reasoning(R): For any non-empty string s, s[len(s)-1] and s[-1] both return the last character.
Strings 365

