Page 376 - Computer Science V2.0 Class 11
P. 376
toggleWord = ''
for indx in range(len(word)):
if indx % 2 == 0:
toggleWord += word[indx]
else:
toggleWord += word[indx].upper()
return toggleWord
word = input("Enter a word : ")
toggleWord = toggleCase(word)
print("The new string is : ", toggleWord)
Assessment
A. Multiple Choice questions.
1. Which of the following operators is not compatible with strings?
a. + b. * c. ** d. in
2. Which of the following statements will return the last two characters of the string, message?
a. message[0:2] b. message[-1:2] c. message[2:0] d. message[-1:-3:-1]
3. Given a string, named, sentence, which of the following statements will return a list of words?
a. sentence.split()
b. sentence.partition()
c. sentence.words()
d. sentence.substr()
4. Consider the following code segment and choose the correct output that will be produced on its execution:
message1 = "Hello how are you?"
ch = '*'
message2 = ch.join(message1)
myList = message2.split()
print(myList[0],myList[-2],sep='#')
a. H*e*l*l*o*#*a*r*e*
b. Hello##are
c. Hello******##are****
d. Error
5. Which of the following functions removes all whitespace characters from the beginning and end of the string?
a. lstrip() b. rstrip() c. allstrip() d. strip()
6. Consider the following string
slogan = "One World One Future"
Which of the following pairs of statements will yield the same output?
a. slogan[2:8] and slogan[-8:-3]
b. slogan[:4] and slogan[10:13]
c. slogan[-1:] and slogan[0:]
d. slogan[4:10:2] and slogan[-12:-16:-2]
362 Touchpad Computer Science (Ver. 2.0)-XI

