Page 332 - Computer Science Class 11 With Functions
P. 332
6. Consider the string given below:
Message = "Beware of dog no 2"
Give the output that will be produced on the execution of each of the following statements:
(i) print(message[3:8])
(ii) print(message[5:])
(iii) print(message[-4:])
(iv) print(message.endswith("2"))
(v) print(message[:4]+message[4:])
(vi) print(message.isalpha())
(vii) print(message[::-3])
(viii) print(message[-4:-14])
(ix) print(message[-2:-14:-1])
(x) print(message.split())
7. Give the output that will be produced on the execution of each of the following code segments:
(i)
>>> message="All IS WEll"
>>> message.find('Is')
(ii)
str1="SunDay#1"
str2=""
k=0
while k<len(str1):
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.
330 Touchpad Computer Science-XI

